How to order results with findBy() in Doctrine

Mirage picture Mirage · Aug 21, 2012 · Viewed 185.7k times · Source

I am using the findBy() method on a Doctrine repository:

$entities = $repository->findBy(array('type'=> 'C12'));

How can I order the results?

Answer

xdazz picture xdazz · Aug 21, 2012

The second parameter of findBy is for ORDER.

$ens = $em->getRepository('AcmeBinBundle:Marks')
          ->findBy(
             array('type'=> 'C12'), 
             array('id' => 'ASC')
           );