Mirage
Mirage

Reputation: 31568

How to order results with findBy() in Doctrine

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

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

How can I order the results?

Upvotes: 170

Views: 251696

Answers (3)

Bhaktaraz
Bhaktaraz

Reputation: 491

$cRepo = $em->getRepository('KaleLocationBundle:Country');

// Leave the first array blank
$countries = $cRepo->findBy(array(), array('name'=>'asc'));

Upvotes: 14

Jethik
Jethik

Reputation: 1876

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

Upvotes: 32

xdazz
xdazz

Reputation: 160963

The second parameter of findBy is for ORDER.

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

Upvotes: 357

Related Questions