标签:
function actionIndex() { $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', ], ], ]); $models = Article::find() ->where(['status' => 1]) ->orderBy($sort->orders) ->all(); return $this->render('index', [ 'models' => $models, 'sort' => $sort, ]); } View: echo $sort->link('name') . ' | ' . $sort->link('age'); foreach ($models as $model) { // display $model here }
标签:
原文地址:http://blog.csdn.net/xiaoyangxiaodong/article/details/45166567