问题
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.
回答1:
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));
}
}
来源:https://stackoverflow.com/questions/19312927/symfony2-fosuserbundle-fosuserevents