FosUserBundle重定向在FilterUserResponseEvent中

Tib*_*Tib 3 php event-listener symfony fosuserbundle

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

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));
}
Run Code Online (Sandbox Code Playgroud)

的services.xml

    <service id="myapp.profile" class="MyApp\UserBundle\EventListener\ProfileListener">
        <tag name="kernel.event_subscriber"/>
        <argument type="service" id="router" />
    </service>
Run Code Online (Sandbox Code Playgroud)

Emi*_*aos 5

为此目的GetResponseUserEvent,在REGISTRATION_CONFIRM事件中,要求回复:

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));
}
Run Code Online (Sandbox Code Playgroud)