[英]FOS UserBundle and getting user
i'm a new Symfony2 developer, i'm using fos UserBundle to manage users and authentication. 我是新的Symfony2开发人员,正在使用fos UserBundle来管理用户和身份验证。 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:
我需要在应用程序中的某个位置(在另一个Bundle中,而不是希望实现FOS UserBUndle的那个)中找到登录用户,我在文档中发现应该使用此服务:
$this->get('security.token_storage')->getToken()->getUser();
but it seems that the 'security.token_storage' was not recognized. 但似乎无法识别“ security.token_storage”。 did i miss some use statements ?
我错过了一些使用说明吗?
The way I do it is using the 'security.context' service like this : 我这样做的方式是使用“ security.context”服务,如下所示:
$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
所以我将其移动到控制器,然后它可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.