我只想重载操作列中的一些按钮,但是当我尝试这样做时,默认按钮不起作用
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
(...)
[
'class' => 'yiigridActionColumn',
'headerOptions'=> ['style'=>'width: 70px;'],
'template' => '{view} {update} {delete}',
'buttons' => [
'view' => function ($url, $model) {
(...)
},
'update' => function ($url, $model) {
(...)
}
],
'urlCreator' => function ($action, $model, $key) {
if ($action === 'view') {
(...)
}
else if ($action === 'update') {
(...)
}
}
],
],
]); ?>
使用上面的代码,'delete'动作不起作用,生成的代码是:
<a title="Elimina" aria-label="Elimina" data-confirm="...?" data-method="post" data-pjax="0">
<span class="glyphicon glyphicon-trash">
</span>
</a>
所以,"delete"动作没有被发送,索引页被重新加载,
你能帮我吗?
这部分导致了这个问题:
'urlCreator' => function ($action, $model, $key) {
if ($action === 'view') {
(...)
}
else if ($action === 'update') {
(...)
}
}
您没有为delete
操作按钮指定url创建,这就是为什么当您点击它时它什么也不做。在urlCreator
回调中为delete
添加条件生成url