yii中有哪些排序方法

yii中有哪些排序方法

展示多条数据时,通常需要对数据按照用户指定的列进行排序。 YII 使用 yiidatasort 对象来代表排序方案的有关信息。 特别地:

Attributes:指定属性,数据按照其排序。 一个属性可以就是简单的一个 model attribute, 也可以是结合了多个 model 属性或者 DB 列的复合属性。下面将给出更多细节:

attributeOrders:给出每个属性当前设置的排序方向。

orders:按照低级列的方式给出排序方向。

使用 yiidataSort,首先要声明什么属性能进行排序。 接着从 attributeOrders 或者 orders 取得当前设置的排序信息, 然后使用它们来自定义数据查询。例如:

use yiidataSort;  $sort = new Sort([     'attributes' => [         'age',         'name' => [             'asc' => ['first_name' => SORT_ASC, 'last_name' => SORT_ASC],             'desc' => ['first_name' => SORT_DESC, 'last_name' => SORT_DESC],             'default' => SORT_DESC,             'label' => 'Name',         ],     ], ]);  $articles = Article::find()     ->where(['status' => 1])     ->orderBy($sort->orders)     ->all();

php中文网,有大量免费的Yii入门教程,欢迎大家学习!

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享