[英]How to use OrderBy in Doctrine with findBY function
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' . 但是我希望结果按“名称”的顺序排列: “ booktest1”,“ booktest2”,“ booktest3”,因为现在的顺序是“ booktest3”,“ booktest1”,“ booktest2” 。
I don't know how to use "orderby" . 我不知道如何使用“ 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. 就像@sdespont所说的那样,订单作为findBy方法的第二个参数传递。
Everything is in doctrine docs : 一切都在学说文档中 :
The EntityRepository#findBy() method additionally accepts orderings, limit and offset as second to fourth parameters:
EntityRepository#findBy()方法还接受排序,限制和偏移作为第二至第四参数:
<?php $tenUsers = $em->getRepository('MyProject\\Domain\\User')->findBy(array('age' => 20), array('name' => 'ASC'), 10, 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.