How to get the current logged User in a service

前端 未结 7 1121
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 20:25

In Symfony 2.8/3.0, with our fancy new security components, how do I get the currently logged User (i.e. FOSUser) object in a service without

7条回答
  •  既然无缘
    2020-12-03 21:10

    From Symfony 3.3, from a Controller only, according this blog post: https://symfony.com/blog/new-in-symfony-3-2-user-value-resolver-for-controllers

    It's easy as:

    use Symfony\Component\Security\Core\User\UserInterface
    
    public function indexAction(UserInterface $user)
    {...}
    

提交回复
热议问题