Access currently logged in user in EntityRepository

后端 未结 3 2091
北恋
北恋 2020-12-11 12:16

I want to create a simple blog example where users have a favourite category attached to there account. This means the can only write articles for this category. (Some of th

3条回答
  •  渐次进展
    2020-12-11 12:44

    You can get user object from Security Context

    $user = $serviceContainer->get('security.context')->getToken()->getUser();
    

    Small tip: In case if user is not logged in - you'll have string in $user, otherwise - User object.

    Cheers ;)

提交回复
热议问题