php Doctrine_Core::getTable()->findAll() 如何指定顺序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7124340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:04:07  来源:igfitidea点击:

Doctrine_Core::getTable()->findAll() how to specify order?

phpsymfony1doctrine

提问by Jake Wilson

When using a Doctrine_Tableobject, is it possible to specify the order of the returned collection when using findAll()or findByWhatever()?

使用Doctrine_Table对象时,是否可以指定使用findAll()or时返回集合的顺序findByWhatever()

In the doc'sI see some stuff about getOrderByStatement()and processOrderBy()but it isn't clear on how to use them...

文档是我看到的一些东西约getOrderByStatement()processOrderBy(),但它不是关于如何使用他们明确的...

回答by Aaron

You can also leave the first array blank

您也可以将第一个数组留空

  $em->getRepository('BackendDestinyBundle:Destiny')->findBy(array(), array('title'=>'asc'));

回答by Gerry

You can in fact specify a default order by in your schema:

实际上,您可以在架构中指定默认顺序:

Foo:
  columns:
    ...
  options:
    orderBy: bar DESC

Note that when you want to specify a different order, you can still create a query and override the default order by.

请注意,当您想要指定不同的顺序时,您仍然可以创建查询并覆盖默认顺序。

回答by Flask

According to Jon Wage you should create a Query in this Case… Found in the mailing-list

根据 Jon Wage 的说法,您应该在这种情况下创建一个查询……在邮件列表中找到

回答by Jorge Ibacache

In my case, the problem was that i had a statement like this

就我而言,问题是我有这样的声明

$destinos  = $em->getRepository('BackendDestinyBundle:Destiny')->findAll();

finaly I changed it to a CreateQuery statement, it does exactly the same but i can put a OrderBy sentence

最后我将其更改为 CreateQuery 语句,它的作用完全相同,但我可以放置一个 OrderBy 语句

$destinos  = $em->createQuery("SELECT d FROM BackendDestinyBundle:Destiny d order by d.name")->getResult();