有人面对过Symfony 3(最后一个版本)这个奇怪的问题吗?
我有以下简单代码:
$repository = $this->getDoctrine()
->getManager()
->getRepository('GeneralRegistrationBundle:Service');
$service = $repository->findOneBy(array('name' => 'Registration'),array('name' => 'ASC'));
$comment = $service->getComment();
$name = $service->getName();
return new Response('le service is '. $name . ', content is ' . $comment);这个密码起作用了。
我清除缓存并使用findBy更改findBy
$service = $repository->findBy(array('name' => 'Registration'),array('name' => 'ASC'),1 ,0);然后,我有以下错误:
错误:调用数组上的成员函数getComment()
有人有想法或线索吗?
提前谢谢。
发布于 2016-08-07 21:18:51
findBy()返回具有给定条件的对象数组。
如果找不到一个空数组,则返回一个空数组。如果只有一行满足您的条件,那么您可以在[0]的最后一个$service添加如下所示:
$service = $repository->findBy(array('name' => 'Registration'),array('name' => 'ASC'),1 ,0)[0];如果没有,则应该使用foreach或其他类似的方法循环遍历查找到的数组。
https://stackoverflow.com/questions/38815175
复制相似问题