[英]Yii: Multiple order by conditions
I am using CActiveDataprovider to show data from different tables. 我使用CActiveDataprovider来显示来自不同表的数据。 Now I am stuck with a problem.
现在我遇到了问题。 I have got two tables (items and categories) and they both have got priority_order columns and I need to show the data using order by both the columns.
我有两个表(项目和类别),他们都有priority_order列,我需要使用两个列的顺序显示数据。
For example: there are two categories and six items belonging to these categories: 例如:属于这些类别的有两个类别和六个项目:
Now I need to show the data in CGridView exactly as they are in above order. 现在我需要完全按照上面的顺序显示CGridView中的数据。 All the food items will come first and will be sorted by their priority_order and drink items will come later;
所有食品都将首先出现,并按优先顺序排序,饮品将在稍后出现; obviously in their order.
显然在他们的顺序。
In ItemsController
I am trying below code (for now order by categories only) 在
ItemsController
我尝试下面的代码(现在只按类别排序)
$dataProvider = new CActiveDataProvider('Items', array(
'criteria' => array(
'with' => array('category'),
'condition' => 'user_id=' . Yii::app()->user->id,
//'order' => 't.priority_order ASC',
'order' => 'category.priority_order ASC',
),
));
I would be happy to provide more details if still not clear enough. 如果仍然不够清楚,我很乐意提供更多细节。 Any help would be appreciated.
任何帮助,将不胜感激。
$dataProvider = new CActiveDataProvider('Items', array(
'criteria' => array(
'with' => array('category'),
'condition' => 'user_id=' . Yii::app()->user->id,
'order' => 'category.priority_order ASC, t.priority_order ASC',
),
));
Giving a second param to the order criteria should work 给订单标准第二个参数应该有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.