我是 Yii2 的初学者。 默认情况下,框架在列表视图中提供“查看|更新|删除”按钮。以下代码显示上述操作按钮。
[
'class' => 'yii\grid\ActionColumn',
...
...
],
现在我想在此 ActionColumn 中添加一个按钮(即立即预订)。我也尝试过使用“按钮”,但出现错误。可能是我没有使用正确。
所以我会感谢你的帮助。
这是如何添加按钮的示例:
[
'class' => 'yii\grid\ActionColumn',
'context' => $this->context,
'buttons' => [
'edit' => function ($model, $key, $index, $instance) {
$urlConfig = [];
foreach ($model->primaryKey() as $pk) {
$urlConfig[$pk] = $model->$pk;
$urlConfig['type'] = $model->type;
}
$url = Url::toRoute(array_merge(['modify'], $urlConfig));
return Html::a('<span class="glyphicon glyphicon-pencil"></span>',
$url, [
'title' => \Yii::t('yii', 'Update'),
'data-pjax' => '0',
]);
},
'remove' => function ($model, $key, $index, $instance) {
$urlConfig = [];
foreach ($model->primaryKey() as $pk) {
$urlConfig[$pk] = $model->$pk;
$urlConfig['type'] = $model->type;
}
$url = Url::toRoute(array_merge(['delete'], $urlConfig));
return Html::a('<span class="glyphicon glyphicon-trash"></span>',
$url, [
'title' => \Yii::t('yii', 'Delete'),
'data-confirm' =>
\Yii::t('yii', 'Are you sure to delete this item?'),
'data-method' => 'post',
'data-pjax' => '0',
]);
}
],
'template' => '{edit}{remove}'
],