php – 返回数组,不是来自Doctrine查询的对象 – Symfony2
发布时间:2020-12-13 13:51:27 所属栏目:PHP教程 来源:网络整理
导读:我使用这个: $this-getDoctrine()-getRepository('MyBundle:MyEntity')-findAll(array(),Query::HYDRATE_ARRAY); 我认为应该确保它返回一个数组的数组,但它仍然返回一个对象数组. 我需要整个结果作为数组的数组返回,所以我可以做这样的事情(愚蠢的例子,但它
我使用这个:
$this->getDoctrine()->getRepository('MyBundle:MyEntity')->findAll(array(),Query::HYDRATE_ARRAY); 我认为应该确保它返回一个数组的数组,但它仍然返回一个对象数组. 我需要整个结果作为数组的数组返回,所以我可以做这样的事情(愚蠢的例子,但它解释了我的意思): <?php $result = $this->getDoctrine()->getRepository('MyBundle:MyEntity')->findAll('return-an-array'); ?> This is the age of the person at the 5th record: <?php echo $result[4]['age']; ?>
根据这个
EntityRepository class,findAll不要多个参数.
下面的代码应该做你想要的 $result = $this->getDoctrine() ->getRepository('MyBundle:MyEntity') ->createQueryBuilder('e') ->select('e') ->getQuery() ->getResult(DoctrineORMQuery::HYDRATE_ARRAY); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |