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:‘‘; } ] ] ]);?>
原文地址:http://quietnight.blog.51cto.com/7163892/1740567