Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Doctrine orm 第2条原则-实体报告的排序方法?_Doctrine Orm - Fatal编程技术网

Doctrine orm 第2条原则-实体报告的排序方法?

Doctrine orm 第2条原则-实体报告的排序方法?,doctrine-orm,Doctrine Orm,有没有一种方法可以使用特定的条件对Doctrine 2EntityRepository对象进行排序,或者如果我想传递特定的排序参数,我是否必须使用DQL查询?您可以通过将第二个参数传递到find\uuuuuuuu方法来返回一组有序的元素,此参数必须是关联数组,其中键是要排序的字段的名称,值为“ASC”或“DESC” // query for one product matching be name and price $product = $repository->findOneBy(ar

有没有一种方法可以使用特定的条件对Doctrine 2
EntityRepository
对象进行排序,或者如果我想传递特定的排序参数,我是否必须使用DQL查询?

您可以通过将第二个参数传递到find\uuuuuuuu方法来返回一组有序的元素,此参数必须是关联数组,其中键是要排序的字段的名称,值为“ASC”或“DESC”

// query for one product matching be name and price
$product = $repository->findOneBy(array('name' => 'foo', 'price' => 19.99));

// query for all products matching the name, ordered by price
$product = $repository->findBy(
    array('name' => 'foo'),
    array('price' => 'ASC')
);


当然,如果您想要一个最复杂的行为,您应该实现一个自定义存储库。

谢谢,这正是我想要的!