Symfony2 FOSUserBundle FOSUserEvents [英] Symfony2 FOSUserBundle FOSUserEvents

查看:208
本文介绍了Symfony2 FOSUserBundle FOSUserEvents的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新定向,如这里,但我的onRegistrationConfirm()事件功能在注册过程中不执行。我的代码与答案相似。我只是不知道有没有更多的事情要做,使我的事件工作。我是新的symfony,所以可能很简单。

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
我猜theere不是像FOSUserEvents :: REGISTRATION_CONFIRM这样的东西,没有什么关于它的这里。但是我发现那里有REGISTRATION_SUCCESS事件,这是我正在寻找的东西。

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));
}
}

这篇关于Symfony2 FOSUserBundle FOSUserEvents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆