简体   繁体   中英

Symfony2 FOSUserBundle FOSUserEvents

I'm trying to do redirection after regiter like here , but my onRegistrationConfirm() Event function is not executed during the registration. My code is similar to that in answer. I just don't know is there is something more to do, to make my event working. I'm new to symfony, so it might be really easy.

OK...so I guess theere is no such thing as FOSUserEvents::REGISTRATION_CONFIRM, there is nothing about it here . But I found there REGISTRATION_SUCCESS event which is exectly what I was looking for.

So my code looks this:

class RegistrationConfirmListener implements EventSubscriberInterface
{
private $router;

public function __construct(UrlGeneratorInterface $router)
{
    $this->router = $router;
}

/**
 * {@inheritDoc}
 */
public static function getSubscribedEvents()
{
    return array(
                FOSUserEvents::REGISTRATION_SUCCESS => 'onRegistrationSuccess'
    );
}

public function onRegistrationSuccess(\FOS\UserBundle\Event\FormEvent $event)
{
    $url = $this->router->generate('my_route');
    $event->setResponse(new RedirectResponse($url));
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM