I've been reading Doctrine's documentation, but I haven't been able to find a way to sort findAll() Results.
I'm using symfony2 + doctrine, this is the statement that I'm using inside my Controller:
$this->getDoctrine()->getRepository('MyBundle:MyTable')->findAll();
but I want the results to be ordered by ascending usernames.
I've been trying to pass an array as an argument this way:
findAll( array('username' => 'ASC') );
but it doesn't work (it doesn't complain either).
Is there any way to do this without building a DQL query?
I use an alternative to the solution that wrote nifr.
It's quicker than the ORDER BY clause, and without the overhead of the Iterator.
This works for me:
Keeping the first array empty fetches back all data, it worked in my case.
Simple:
You need to use a criteria, for example:
Try this:
It's useful to look at source code sometimes.
For example
findAll
implementation is very simple (vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php
):So we look at
findBy
and find what we need (orderBy
)