Symfony2 FOSUserBundle FOSUserEvents

2019-08-10 00:36发布

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条回答
霸刀☆藐视天下
2楼-- · 2019-08-10 01:29

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));
}
}
查看更多
登录 后发表回答