编程语言
首页 > 编程语言> > php – 在FilterUserResponseEvent中重新定位FosUserBundle

php – 在FilterUserResponseEvent中重新定位FosUserBundle

作者:互联网

我想点击注册链接后重定向我的用户,但我被卡住了,因为FilterUserResponseEvent中没有setResponse方法

RegistrationListenner.php

public static function getSubscribedEvents()
{
    return array(
        FOSUserEvents::REGISTRATION_CONFIRMED => 'onRegistrationConfirmed',
    );
}


public function onRegistrationConfirmed(FilterUserResponseEvent $event)
{
    $url = $this->router->generate('my_route', array('foo' => 'bar'));
    $response = new RedirectResponse($url);
    $event->setResponse(new RedirectResponse($url));
}

的services.xml

    <service id="myapp.profile" class="MyApp\UserBundle\EventListener\ProfileListener">
        <tag name="kernel.event_subscriber"/>
        <argument type="service" id="router" />
    </service>

解决方法:

为此,在REGISTRATION_CONFIRM事件中有GetResponseUserEvent,它要求响应:

public static function getSubscribedEvents()
{
    return array(
            FOSUserEvents::REGISTRATION_CONFIRM => 'onRegistrationConfirm',
    );
}

public function onRegistrationConfirm(GetResponseUserEvent $event)
{
    $url = $this->router->generate('my_route', array('foo' => 'bar'));
    $response = new RedirectResponse($url);
    $event->setResponse(new RedirectResponse($url));
}

标签:event-listener,php,symfony,fosuserbundle
来源: https://codeday.me/bug/20190831/1773746.html