Symfony从Controller访问实体变量

时间:2015-12-01 18:46:21

标签: symfony variables entity

我不知道怎么办不起。我有它的工作,搞砸了我的PHP服务器&没有来自工作版本的备份...我想我有类似的解决方案。

public function schreibenAction() {
  $user = $this->getDoctrine()
          ->getRepository('AppBundle:User')
          ->find(1); //How can I search for the currently logged user?

  if (!$user) {
      throw $this->createNotFoundException(
              'No user found for id 1'
      );
  }

  $path = $user->getPath();
  return $this->render('default/unterlagen/schreiben.html.twig', array(
              'path' => $path,
    ));
}

我需要数据库中的路径值..

SELECT t0.id AS id_1, t0.username AS username_2, t0.password AS password_3, t0.path AS path_4, t0.is_active AS is_active_5 FROM app_users t0 WHERE t0.id = ?

1 个答案:

答案 0 :(得分:1)

您可以在控制器中使用$ this-> getUser()获取当前登录的用户。请看this