1 回答
TA贡献1853条经验 获得超18个赞
如果您只想在 dataProvider 不为 null 时显示 gridview,那么您应该以这种方式检查
<?php
if ($detProvider !== null) {
echo GridView::widget([
'dataProvider' => $detProvider,
//'filterModel' => $searchModel1,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
// 'id',
'first_name',
'last_name',
'email',
/*'application_id',*/
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view}',
'buttons' => [
'view' => function ($url, $model, $key) {
return Yii::$app->user->can('viewApplicant') ? Html::a(Html::tag('span', '', ['class' => "glyphicon glyphicon-eye-open"]), $url, ['title' => Yii::t('yii', 'View')]):"";
},
/*'edit' => function ($url, $model, $key) {
return Yii::$app->user->can('editApplicant') ? Html::a(Html::tag('span', '', ['class' => "glyphicon glyphicon-pencil"]), $url, ['title' => Yii::t('yii', 'Edit')]):"";
},
'delete' => function ($url, $model, $key) {
return Yii::$app->user->can('deleteApplicant') ? Html::a(Html::tag('span', '', ['class' => "glyphicon glyphicon-trash"]), $url, ['title' => Yii::t('yii', 'Delete'), 'data' => ['method' => 'post', 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), 'params' => ['id' => $model['id'], '_csrf' => Yii::$app->request->csrfToken]]]):"";
},*/
],
'urlCreator' => function($action, $model, $key, $index) {
if ($action === 'view') {
$url = 'index.php?r=admin/applicant/view&id=' . $model['id'];
return $url;
}
}
],
],
]);
}
?>
- 1 回答
- 0 关注
- 105 浏览
添加回答
举报