Php Doctrine findBy()从实体调用方法
我需要一些帮助来从实体调用方法 这是我试图执行的代码Php Doctrine findBy()从实体调用方法,php,symfony,doctrine,Php,Symfony,Doctrine,我需要一些帮助来从实体调用方法 这是我试图执行的代码 $datat = $this->getDoctrine() ->getRepository('AppBundle:users') ->findBy(array('userId' => $userId)); 在这之后,当我打电话的时候 $data->getUser(); 我收到一条关于exeption“Error:对非对象调用成员函数getUser()”的消息 当我转储$data时,我从表中获取数据,或
$datat = $this->getDoctrine()
->getRepository('AppBundle:users')
->findBy(array('userId' => $userId));
在这之后,当我打电话的时候
$data->getUser();
我收到一条关于exeption“Error:对非对象调用成员函数getUser()”的消息
当我转储$data时,我从表中获取数据,或者如果我执行->find()
带有ID值。findBy
通常返回一个ArrayCollection
您应该改用findOneBy
,以便只针对一个实体
因此:
findBy
通常返回ArrayCollection
您应该改用findOneBy
,以便只针对一个实体
因此:
您的方法getUser()在users实体中不存在
只需迭代您的$datat
,然后像这样从用户对象调用方法
foreach ($users as $user) {
// $user is an instance of users
echo $user->getName(); //if this method exist in your entity model
}
您的方法getUser()在users实体中不存在
只需迭代您的$datat
,然后像这样从用户对象调用方法
foreach ($users as $user) {
// $user is an instance of users
echo $user->getName(); //if this method exist in your entity model
}
$datat
!=$data
$datat
!=<代码>$data