When I am using this function:
$TopItemList = $app['orm.em']->getRepository('\Eccube\Entity\Product')
->findBy(array('name' => array('booktest1', 'booktest2', 'booktest3')));
But I want the results in 'name' order by: 'booktest1', 'booktest2', 'booktest3' because now order is 'booktest3', 'booktest1', 'booktest2' .
I don't know how to use "orderby" .
Here is the way to order your entities
$TopItemList = $app['orm.em']
->getRepository('\Eccube\Entity\Product')
->findBy(
array('name'),
array(
'booktest1' => 'ASC',
'booktest2' => 'ASC',
'booktest3' => 'ASC'
)
);
As @sdespont said, order is passed as a second argument of findBy method.
Everything is in doctrine docs :
The EntityRepository#findBy() method additionally accepts orderings, limit and offset as second to fourth parameters:
<?php $tenUsers = $em->getRepository('MyProject\\Domain\\User')->findBy(array('age' => 20), array('name' => 'ASC'), 10, 0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.