2014-11-04 129 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