Symfony2 FOSUserBundle FOSUserEvents

断了今生、忘了曾经 提交于 2019-12-24 14:24:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!