In Yii2’s GridView::Widget,data-method=>post, the request method is the investigation and analysis of GET
1. In Yii2’s GridView::Widget,data-method=>post, the request method is GET.
$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('', [
'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. It was later discovered that the cause was that yii.js was not loaded. But the layout file exists 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. The final discovery is that the reason is that the layout file does not exist
<?php $this->endBody() ?>