2

我尝试为用户进入系统记录时创建一个事件,

我有这个代码:

services:
    login_listener:
        class: mio\mioBundle\LoginListener
        tags:
            - { name: kernel.event_listener, event: security.interactive_login, method: onSecurityInteractiveLogin }
<?php

namespace mio\mioBundle;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\EventDispatcher\Event;

class LoginListener
{

    public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
    {

    }
}
?>

但是在探查器中没有所谓的监听器是什么?

4

2 回答 2

1

创建一个服务实现AuthenticationSuccessHandlerInterface并将其设置为防火墙中的成功处理程序——success_handler安全配置参考页面上搜索。您可以在该onAuthenticationSuccess()方法中实现您需要的任何逻辑。

于 2012-10-04T12:40:36.030 回答
1

您的代码是正确的方法。探查器显示未调用事件可能是登录后重定向的原因。探查器向您显示最新请求 - 重定向后的请求。如果您检查最后一个 POST 请求(到 login_check)的分析器信息,您会发现该事件实际上已被调用。

工作示例:http ://www.metod.si/login-event-listener-in-symfony2/

于 2013-11-26T14:36:46.000 回答