【发布时间】:2016-08-07 14:32:29
【问题描述】:
有人遇到过 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);
此代码有效。
我清除缓存并将findOneBy 更改为findBy:
$service = $repository->findBy(array('name' => 'Registration'),array('name' => 'ASC'),1 ,0);
然后我有以下错误:
错误:调用数组上的成员函数 getComment()
有人有想法或线索吗?
提前致谢。
【问题讨论】:
-
您期待什么? findOne 返回一个且只有一个对象。 find 总是返回一个包含 0 个或多个对象的数组。
-
呼……我现在需要去度假……谢谢 Cerad
-
解决了吗?如果是这样,请标记或发布答案并接受。