How to order results with findBy() in Doctrine

PhpDoctrine Orm

Php Problem Overview


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

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

How can I order the results?

Php Solutions


Solution 1 - Php

The second parameter of findBy is for ORDER.

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

Solution 2 - Php

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

Solution 3 - Php

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMirageView Question on Stackoverflow
Solution 1 - PhpxdazzView Answer on Stackoverflow
Solution 2 - PhpJethikView Answer on Stackoverflow
Solution 3 - PhpBhaktarazView Answer on Stackoverflow