Symfony getting logged in user's id

后端 未结 5 683
独厮守ぢ
独厮守ぢ 2020-12-05 09:35

I am developing an application using Symfony2 and doctrine 2. I would like to know how can I get the currently logged in user\'s Id.

5条回答
  •  离开以前
    2020-12-05 09:36

    For finding by username:

    public function getLoggedUser()
        {
            $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
            return $this->getUser();
        }
    

    Then

    $this->getLoggedUser()->getUsername() will return the username.
    

提交回复
热议问题