所以我有这段代码:
<?= GridView::widget([
'dataProvider' => $detProvider,
//'filterModel' => $searchModel1,
if ($detProvider !== null) {
'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;
}
}
],
],
}
]); ?>
我放置该 if 语句是因为我希望仅当 detProvider 不为 null 时才显示此特定表。但是我收到一个解析错误;
ParseError 语法错误,意外的“if”(T_IF),期待“]”
有人可以帮忙吗?我究竟做错了什么??我还是 yii2 和 php 的新手。
慕容森