How to sort findAll Doctrine's method?

前端 未结 12 2146
闹比i
闹比i 2020-12-23 00:14

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 statemen

12条回答
  •  清酒与你
    2020-12-23 01:05

    I use an alternative to the solution that wrote nifr.

    $resultRows = $repository->fetchAll();
    uasort($resultRows, function($a, $b){
        if ($a->getProperty() == $b->getProperty()) {
            return 0;
        }
        return ($a->getProperty()< $b->getProperty()) ? -1 : 1;
    });
    

    It's quicker than the ORDER BY clause, and without the overhead of the Iterator.

提交回复
热议问题