【发布时间】:2017-10-30 16:19:35
【问题描述】:
我在更改密码提交时的监听事件有问题。
这里是听众
public function __construct(
UrlGeneratorInterface $router,
Session $session,
TokenStorageInterface $tokenStorage
) {
$this->router = $router;
$this->session = $session;
$this->tokenStorage = $tokenStorage;
}
public static function getSubscribedEvents()
{
return [
FOSUserEvents::CHANGE_PASSWORD_SUCCESS => [
['onChangePasswordSuccess', +10000]
],
];
}
public function onChangePasswordSuccess(GetResponseUserEvent $event)
{
$this->tokenStorage->setToken(); // logout user
$this->session->invalidate();
$event->setResponse(new RedirectResponse($this->router->generate('fos_user_security_login')));
}
但是什么也没发生。我在 $this->tokenStorage->setToken() 上放置了调试器断点,但它并没有停止。 有人可以帮我弄清楚为什么这不起作用
【问题讨论】:
-
你在
services.yml注册了这个监听器吗?你能展示一下它的配置吗? -
CoreBundle\EventListener\ChangePasswordListener: tags: - { name: kernel.event_subscriber } 首先我放了这个,但它没有用。然后我删除了,因为我使用了 autowire 并且也没有工作
-
我猜你应该在你的服务配置中添加这样的东西。gist.github.com/kaduev13/b569ed0d53af70a4bc697bf7ee88c8bc
-
另外,请检查此
services.yml是否已加载。
标签: php symfony fosuserbundle