我试图重定向新用户,欢迎使用侦听器注册后的页面。但我没有结果。我确实喜欢在那一页上说Stackoverflow。请帮帮忙。以下是代码:
namespace Acme\UserBundle\EventListener;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* Listener responsible to change the redirection at the end of the password resetting
*/
class RegistrationConfirmListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_CONFIRM => 'onRegistrationConfirm'
);
}
public function onRegistrationConfirm(GetResponseUserEvent $event)
{
$url = $this->router->generate('_welcome');
$event->setResponse(new RedirectResponse($url));
}
}我的服务是:
<service id="acme_user.registration.confirmed" class="Acme\UserBundle\EventListener\RegistrationConfirmListener">
<tag name="kernel.event_subscriber"/>
<argument type="service" id="router"/>
</service>发布于 2014-09-08 09:01:41
我只需要使用REGISTRATION_SUCCESS而不是REGISTRATION_CONFIRM。而且一切都很好。
https://stackoverflow.com/questions/25718906
复制相似问题