相关疑难解决方法(0)

用户登录Symfony 2.3后执行功能

我试图在用户登录FOSUserBundle后执行一个函数,在我的config.yml中我设置了服务:

services:
    authentication.success.listener:
        class: MyCompany\MyBundle\EventListener\AuthenticationEventListener
        arguments: [@router]
        tags:
            - { name: kernel.event_subscriber }
Run Code Online (Sandbox Code Playgroud)

然后,我用方法创建Listener类:

<?php

namespace MyCompany\MyBundle\EventListener;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\UserEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Cookie as Cookie;

class AuthenticationEventListener implements EventSubscriberInterface
{    
    private $router;

    public function __construct(UrlGeneratorInterface $router)
    {
         $this->router = $router;
    }

    public static function getSubscribedEvents()
    {
        return array(
                FOSUserEvents::SECURITY_IMPLICIT_LOGIN => 'onAuthenticationSuccess',
        );
    }

    public function onAuthenticationSuccess(UserEvent $event)
    {
        //my actions goes here...
    }

}

?>
Run Code Online (Sandbox Code Playgroud)

当我尝试登录时,之后没有任何反应,我写了一些错误的代码来生成异常,但一切顺利......显然这个功能并没有被排除在外.

有什么帮助吗?

symfony fosuserbundle symfony-2.3

2
推荐指数
1
解决办法
2551
查看次数

标签 统计

fosuserbundle ×1

symfony ×1

symfony-2.3 ×1