在 Yii2 的 GridView::widget 中,’data-method’ => ‘post’ ,请求方式是 GET 的排查分析
1、在 Yii2 的 GridView::widget 中,’data-method’ => ‘post’ ,请求方式是 GET。
<?php
echo GridView::widget([
'dataProvider' => $dataProvider,
'tableOptions' => ['class' => 'table table-centered table-nowrap table-striped mb-0'],
'rowOptions' => function ($model, $key, $index, $grid) {
return ['id' => "tr_{$key}"];
},
'options' => [
'id' => 'grid',
'class' => 'grid-view',
'style' => "position: relative; overflow: auto; width: 100%;"
],
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{messages} {abort}',
'buttons' => [
'abort' => function ($url, $model, $key) {
if ($model->state == PhoneMessageTask::STATE_WAIT || $model->state == PhoneMessageTask::STATE_WAITING_FOR_SENDING) {
return Html::a('<i class="mdi mdi-stop-circle"></i>', [
'abort',
'id' => $model->id
], [
'class' => 'action-icon remark-btn',
'title' => '中止',
'data-confirm' => '确定要中止该任务吗?',
'data-method' => 'post',
]);
}
return null;
},
],
],//end ActionColumn
],
'emptyText' => '暂无信息', //没有数据时显示的信息
'emptyTextOptions' => ['style' => 'text-align:center;'], //没有数据时显示信息的样式设置
'showOnEmpty' => true, //没有数据时是否显示表格
'summary' => '共{totalCount}条信息,共{pageCount}页,当前{begin}-{end}条',
'pager' => [
'options' => ['class' => 'hidden']
]
]);
?>
2、后来发现原因在于 yii.js 未加载。但是布局文件中是存在 AppAsset::register($this);
<?php
namespace management\assets;
use yii\web\AssetBundle;
/**
* Main management application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
// 'yii\bootstrap4\BootstrapAsset',
];
}
3、最后发现原因在于布局文件中不存在 endBody() ?>
近期评论