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

yii2 GridView使用记录

时间:2016-02-02 07:32:50      阅读:372      评论:0      收藏:0      [点我收藏+]

标签:yii2   gridview   

controller

public function actionIndex(){
    $myUser = new MyUser();
    $myuserQuery =  $myUser::find()->select([‘fuid‘,‘fusername‘,‘femail‘,‘fstatus‘,‘fname‘])->join(‘ LEFT JOIN‘,‘wanguan_roles‘,‘wanguan_admin.frule = wanguan_roles.fid‘);
    $listDataProvider = new ActiveDataProvider([
        ‘query‘ => $myuserQuery,
        ‘pagination‘ => [
            ‘pageSize‘ => 50,
        ],
    ]);
   return $this->render(‘list‘, [‘listDataProvider‘ => $listDataProvider]);
}

view

 <?php echo GridView::widget([
     ‘summary‘=>false,
     ‘dataProvider‘ => $listDataProvider,
     ‘pager‘=>[
         ‘firstPageLabel‘=>‘首页‘,
         ‘lastPageLabel‘=>‘尾页‘,
         ‘nextPageLabel‘=>‘下一页‘,
         ‘prevPageLabel‘=>‘上一页‘,
         ‘maxButtonCount‘=>6,
     ],
     ‘columns‘=>[
         [
             ‘attribute‘=>‘fusername‘,
             ‘label‘=>‘用户名‘,
         ],
         [
             ‘attribute‘=>‘femail‘,
             ‘label‘=>‘邮箱‘
         ],
         [
             ‘attribute‘=>‘fstatus‘,
             ‘label‘=>‘状态‘,
             ‘format‘=>‘raw‘,
             ‘value‘=>function($model){
                 return $model[‘fstatus‘]==1?Html::tag(‘span‘,‘有效‘,[‘class‘=>‘label label-success‘,‘id‘=>$model[‘fuid‘],‘data‘=>[‘id‘=>$model[‘fuid‘]]]):Html::tag(‘span‘,‘无效‘,[‘class‘=>‘label label-default‘,‘id‘=>$model[‘fuid‘],‘data‘=>[‘id‘=>$model[‘fuid‘]]]);
             }
         ],
         [
             ‘attribute‘=>‘fname‘,
             ‘label‘=>‘角色‘,
             ‘value‘=>function($model){
                 return isset($model->fname)?$model->fname:‘‘;
             }
         ]
     ]
]);?>


yii2 GridView使用记录

标签:yii2   gridview   

原文地址:http://quietnight.blog.51cto.com/7163892/1740567

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