我的控制器中有 $id 它是一个外键
  $query = $em->getRepository('SurgeryPatientBundle:Patients')->findPatientByUserID($id);
在我的存储库文件中,这个函数
 public function findPatientByUserID($id)
{
    return $this->getEntityManager()
        ->createQuery('SELECT p FROM SurgeryPatientBundle:Patients p WHERE p.user ='.$id.'')
        ->execute();
}
我想得到一个对象的实例,但仍然得到一个数组。使用 find($id) 查询效果很好
编辑问题解决了,我太笨了,我调用了 $query[0]