i'm a new Symfony2 developer, i'm using fos UserBundle to manage users and authentication. i need to get the logged in user somewhere in my application (in another Bundle , not in the one in wish i implemented the FOS UserBUndle) i found in the documentation that i should use this service:
$this->get('security.token_storage')->getToken()->getUser();
but it seems that the 'security.token_storage' was not recognized. did i miss some use statements ?
The way I do it is using the 'security.context' service like this :
$user = $this->container->get('security.context')->getToken()->getUser();
Or even easier:
$user = $this->getUser();
i found the solution : i used this manipulation in a service or it shouldn't be. so i move it to the controller and then it works
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.