I need to fetch all records in database as Array using findAll()
in Doctrine, My Query is Something like this
$result = $this->getDoctrine()
->getRepository('CoreBundle:Categories')
->findAll(\Doctrine\ORM\Query::HYDRATE_ARRAY);
even if set Hydration Mode to HYDRATE_ARRAY
, am getting results as objects
array:4 [▼
0 => Categories {#323 ▶}
1 => Categories {#326 ▶}
2 => Categories {#329 ▶}
3 => Categories {#332 ▶}
]
what mistake i made?
The findAll()
method does not have any parameters. You can, for example, use the repository's createQueryBuilder()
method to achieve what you want to do:
use Doctrine\ORM\Query;
// ...
$query = $this->getDoctrine()
->getRepository('CoreBundle:Categories')
->createQueryBuilder('c')
->getQuery();
$result = $query->getResult(Query::HYDRATE_ARRAY);
It's possible to use $query->getArrayResult()
as a shortcut to $query->getResult(Query::HYDRATE_ARRAY)
doctrine hydration modes
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