温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

yii2 GridView使用记录

发布时间:2020-06-11 15:53:14 来源:网络 阅读:1141 作者:hello_world007 栏目:开发技术

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:'';
             }
         ]
     ]
]);?>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI