FOSuserbundleを使用してユーザー登録を開始していますhttps://github.com/FriendsOfSymfony/FOSUserBundle
登録/ログインとログアウトがあります。私が今やりたいのは、ログインしているユーザーのデータを取得して、サイトのすべてのページに表示することです。ヘッダータイプの「Hiusername」のように。
私のapp/Resources / views / base.html.twigにコントローラーを埋め込むのが、これを行うための最良の方法のようですhttp://symfony.com/doc/current/book/templating.html#embedding-controllers
そこで、ユーザープロファイルデータにアクセスするためのコントローラーを作成しました。私が理解できないのは、組み込みコントローラーでFOSメソッドにアクセスする方法です。だから私のAcme/UserBundle / Controller / UserController.phpからこれをやりたい:
public function showAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException(
'This user does not have access to this section.');
}
return $this->container->get('templating')
->renderResponse('FOSUserBundle:Profile:show.html.'.$this->container
->getParameter('fos_user.template.engine'), array('user' => $user));
}
私が入手したもの:vendor / bundles / FOS / UserBundle / Controller / ProfileController.php