简体   繁体   English

FOS UserBundle和获取用户

[英]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.

相关问题 Symfony2,FOS用户捆绑包,需要完全验证才能访问此资源 - Symfony2, FOS userbundle, Full authentication is required to access this resource Symfony2安全性 - 用户“Ibw \\ UserBundle \\ Entity \\ User”没有用户提供程序 - Symfony2 security - There is no user provider for user “Ibw\UserBundle\Entity\User” 对symfony2和fos用户进行多重检查 - Mutltiple check on symfony2 and fos User UserBundle Symfony 2 - UserBundle Symfony 2 fos 用户:即使用户只有一个角色,也允许路由到多个角色 - fos user: allow route to many roles even if user have just one role 电子邮件验证后自动登录并重定向到“ fos_user_profile_edit”路径 - Auto-login after email validation and redirection to 'fos_user_profile_edit' path Symfony fos_user在Laravel中捆绑编码密码 - Symfony到Laravel Migration - Symfony fos_user bundle encoded password in Laravel - Symfony to Laravel Migration 通过JS获取用户个人详细信息 - Getting a user personal details through JS 可捕获的致命错误:传递给UserBundle \\ Form \\ UserType :: __ construct()的参数2必须是实例? - Catchable Fatal Error: Argument 2 passed to UserBundle\Form\UserType::__construct() must be an instance ? 在Java RESTful资源中获取用户信息 - Getting user info in java RESTful resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM