I'm using this:
$this->getDoctrine()->getRepository('MyBundle:MyEntity')->findAll(array(), Query::HYDRATE_ARRAY);
I thought that should ensure it returns an array of an array, but it still returns an array of objects.
I need the whole result returned as an array of an array so I can do this kind of thing (silly example, but it explains what I mean):
<?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']; ?>
According to this EntityRepository class, findAll
don't take multiple arguments.
The code below should do what you want
$result = $this->getDoctrine()
->getRepository('MyBundle:MyEntity')
->createQueryBuilder('e')
->select('e')
->getQuery()
->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
You can also use the getArrayResult()
function instead of getResult()
. It returns an array of data instead:
$query = $em->createQuery("SELECT test FROM namespaceTestBundle:Test test");
$tests = $query->getArrayResult();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With