YII2 Gridview

YII2 Gridview 部分使用规则

1.页面显示的时间戳转换
a.

[
        'label'=>'创建日期',
        'attribute' => 'created_at',
        'filter' => false, //不显示搜索框 'value' => function($data) { return date('Y-m-d H:i:s',$data->created_at); } ], 

b.

[
        'label'=>'创建日期',
        'attribute' => 'created_at',
        'format' => ['date', 'php:Y-m-d H:i:s'], ], 

2.为字段加超链接

[ 
      'attribute'=>'title’,
      'format'=>'raw’,
      'value'=> function($data){return Html::a($data->title,['exam/index', 'id' => $data->_id],['title' => '审核']);} ], [ 'label'=>'更多操作’, 'format'=>'raw’, 'value' => function($data) { $url = "http://www.baidu.com”; return Html::a('添加权限组', $url, ['title' => '审核']); } ], 

3.下拉菜单搜索

[
            'label' => '当前状态',
            'attribute' => 'status',
            'filter' => Html::dropDownList('AppBaseSearch[status ]',$searchModel-> status, [ '' => '请选择', ‘0' => '审核拒绝', ‘1' => '审核通过', ]), 'value' => function($date) { switch ($date-> status) { case 1'; return '审核通过'; break; case ‘0'; return '审核拒绝'; break; default: return '未知状态'; break; } } ], 

4.私人定制增删改按钮

[
                'header' => "查看/审核",
                'class' => 'yii\grid\ActionColumn',
                'template'=> '{view} {update} {delete}', 'headerOptions' => ['width' => '140'], 'buttons' => [ 'view' => function ($url, $model, $key) { return Html::a(Html::tag('span', '', ['class' => "glyphicon fa fa-eye"]), ['admin/view-app', 'id'=>$model->app_id], ['class' => "btn btn-xs btn-success", 'title' => '查看']); }, 'update' => function ($url, $model, $key) use($uid){ return Html::a('通过', ['admin/reviewapp','id'=>$model->app_id, 'status’=>1], ['class' => "btn btn-xs btn-info"]); }, 'delete' => function ($url, $model, $key) { return Html::a('拒绝', ['admin/reviewapp', 'id' => $model->app_id, 'status’=>0], ['class' => "btn btn-xs btn-danger"]); } ] ], 

转载于:https://www.cnblogs.com/GaoAnLee/p/5197773.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值