码迷,mamicode.com
首页 > 其他好文 > 详细

Yii2 sort

时间:2015-04-21 11:18:52      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

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
 }

Yii2 sort

标签:

原文地址:http://blog.csdn.net/xiaoyangxiaodong/article/details/45166567

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!