Yii2:如何在 Find() 的 orderby() 中添加两个字段

2022-01-07 00:00:00 php yii2

如何在find()方法中添加多个字段进行排序?

How to add more than one field to sort in find() method?

我尝试过如下

$model::find()->orderBy([['id_date' => SORT_DESC],['item_no'=>SORT_ASC]);

但是它在查询时抛出错误.yii2 产生的 Orderby Query 为:ORDER BY 0, 1

But it is throwing error with query. Orderby Query produced by yii2 is: ORDER BY 0, 1

推荐答案

根据文档:

$model::find()->orderBy([
  'id_date' => SORT_DESC,
  'item_no'=>SORT_ASC
]);

相关文章