2014-11-04 128 views
0

我需要您的帮助来保护存储库。在我的网站上,我有SonataAdminBundle + FOSUserBundle。保护Symfony2中的目录

在奏鸣曲管理页面(/ admin)上登录后,我想在其他页面(/ test)中获取连接的用户标识。

我的控制器:

class CkeditorController extends Controller 
{ 
    public function indexAction() 
    { 
    # How to get the user id ? 

    } 
} 

最好的问候,

回答

0

您可以尝试

$this->getUser()->getId()

这是一个捷径

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

查看Documentation

+0

谢谢你,问题是防火墙 – Dimitri 2014-11-04 13:04:28