我想在注册后将用户重定向到另一个表单,然后他才能访问我网站上的任何内容(例如在https://github.com/FriendsOfSymfony/FOSUserBundle/issues/387中)。
所以我在文档中创建了一个 eventListener :
<?php
namespace rs\UserBundle\EventListener;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\UserEvent;
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 RegistrationConfirmedListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_CONFIRMED => 'onRegistrationConfirmed'
);
}
public function onRegistrationConfirmed()
{
$url = $this->router->generate('rsWelcomeBundle_check_full_register');
$response = new RedirectResponse($url);
return $response;
}
}
服务.yml:
services:
rs_user.registration_completed:
class: rs\UserBundle\EventListener\RegistrationConfirmedListener
arguments: [@router]
tags:
- { name: kernel.event_subscriber }
但它不起作用,用户注册,他点击他邮箱中的确认链接,他没有重定向到我想要的页面,他已经登录,我只有说帐户已确认的消息。
为什么它没有像我想要的那样将我重定向到路线:rsWelcomeBundle_check_full_register?
谢谢