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' => 'yiigridActionColumn',
'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"]);
}
]
],