Events FOSUserBundle Symfony2 on register and login

前端 未结 1 692
面向向阳花
面向向阳花 2021-02-04 20:05

I\'m trying to implement events on FOSUserBundle



        
1条回答
  •  半阙折子戏
    2021-02-04 20:45

    Two points:

    1. In the service definition - { name: 'kernel.event_subscriber'} is enough, no event entry. This the difference between subscriber and listener. A listener can only listen to one event, defined trough event and method params in the service definition. A subscriber can listen to multiple events, defined trough the method getSubscribedEvents(), so no further params in the service definition needed.

    2. Second point, you are type hinting against the event classes (UserEvent andFilterUserResponseEvent), but you never imported them, so PHP assumes them in the same namespace (as said in the error message).

      use FOS\UserBundle\Event\UserEvent;
      use FOS\UserBundle\Event\FilterUserResponseEvent;
      

    0 讨论(0)
提交回复
热议问题