문제

I want to redirect my user after he clicks on the registration link but I'm stuck because there is no setResponse method in a 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));
}

services.xml

    <service id="myapp.profile" class="MyApp\UserBundle\EventListener\ProfileListener">
        <tag name="kernel.event_subscriber"/>
        <argument type="service" id="router" />
    </service>
도움이 되었습니까?

해결책

For this purpose there is the GetResponseUserEvent at the REGISTRATION_CONFIRM event, which asks for a response:

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

다른 팁

in my version $event doesn't have setResponse() method but encapsulate the RedirectResponse object.

As object has already passed by reference you can use the setTargetUrl() to change the target url of the RedirectResponse.

You can do the redirection with this line :

$event->getResponse()->setTargetUrl("http://panel.it-strategy.fr")));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top