简体   繁体   English

如何使用findBY函数在教义中使用OrderBy

[英]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.

相关问题 如何将“ findby”学说与输入作为数组一起使用? - how to use “findby” doctrine with input as array? 如何使用查询/结果缓存(Doctrine 1.2)使Doctrine查找(如Doctrine_table-&gt; find,-&gt; findby *) - How to make Doctrine lookups like Doctrine_table->find, ->findby* use the query/results cache (doctrine 1.2) 如何在Doctrine中使用findBy()来订购结果 - How to order results with findBy() in Doctrine 如何在Doctrine查询生成器的“ orderBy()”上使用更高级的参数? - How to use more advanced parameters on Doctrine query builder's 'orderBy()'? 如何将数组传递给 doctrine 查询 findBy? - How to pass array into the doctrine query findBy? 如何在Laravel中的orderBy函数中使用substr() - How to use substr() inside an orderBy function in Laravel 为 findBy 准则存储库函数返回具有特定键的关联数组 - Return an associative array with certain key for a findBy doctrine repository function 使用Doctrine魔术“findby”方法进行制作是否安全? 或者它们仅用于原型设计? - Is it safe to use Doctrine magic “findby” methods for production? Or are they only for prototyping? Symfony2学说在findBy函数的外键上传递参数 - Symfony2 doctrine passing a parameter on foreign key in findBy function 学说:如何使用替换功能 - Doctrine : how to use Replace function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM