我试图像regiter后做重定向在这里 ,但在注册时不执行我的onRegistrationConfirm()事件函数。 我的代码是在回答类似。 我只是不知道是有什么更多的事情要做,以使我的工作情况。 我是新来的symfony,所以它可能是很容易的。
Answer 1:
OK ......所以我想theere是FOSUserEvents :: REGISTRATION_CONFIRM没有这样的事,没有什么关于它在这里 。 但是我发现有REGISTRATION_SUCCESS事件是exectly什么,我一直在寻找。
所以我的代码看起来这样的:
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));
}
}
文章来源: Symfony2 FOSUserBundle FOSUserEvents