[英]How can I order results by conditions in Doctrine?
How can I order results with the Doctrine Query Builder so that the results matching the first condition go first, then the results of the second condition (and all results should be matching the third condition)? 如何使用“ Doctrine查询生成器”对结果进行排序,以使匹配第一个条件的结果排在第一位,然后是第二个条件的结果(所有结果都应与第三个条件匹配)?
Here is an example of the query: 这是查询的示例:
$QB->select('k', 'k.word')
->from($repository, 'k')
->where('k.word LIKE :strict')
->orWhere('k.word LIKE '.':loose')
->andWhere('k.status=1')
->setMaxResults(5)
->setParameter('strict', $query.'%')
->setParameter('loose', '%'.$query.'%');
I tried to play with orderBy()
but it didn't work out - don't know what syntax could be.... 我尝试使用
orderBy()
但没有成功-不知道语法是什么。
Upd. UPD。 Example list of data and result: Let's say I have a list of data:
数据和结果列表示例:假设我有一个数据列表:
And the search query is "ca" . 搜索查询是“ ca” 。
I want the query to order and show these results first: 我希望查询进行排序并首先显示这些结果:
Then this result: 然后这个结果:
And filter out this one, because the status is 0 : 并过滤掉这个,因为状态为0 :
Have you tried this ? 你尝试过这个吗?
$QB->select('k', 'k.word')
->from($repository, 'k')
->where('k.word LIKE :strict')
->orWhere('k.word LIKE '.':loose')
->andWhere('k.status=1')
->setMaxResults(5)
->setParameter('strict', $query.'%')
->setParameter('loose', '%'.$query.'%')
->orderBy('k.word', 'ASC');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.