我正在使用这个:
$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']; ?>
根据这个实体存储库类 https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/EntityRepository.php#L162, findAll
不要接受多个参数。
下面的代码应该做你想要的
$result = $this->getDoctrine()
->getRepository('MyBundle:MyEntity')
->createQueryBuilder('e')
->select('e')
->getQuery()
->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)