1、在 Yii2 的 GridView::widget 中,’data-method’ => ‘post’ ,请求方式是 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、后来发现原因在于 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、最后发现原因在于布局文件中不存在
<?php $this->endBody() ?>
PHP / Laravel / Yii2 老项目维护与长期技术支持
如果你的 PHP / Laravel / Yii2 项目已经上线,但遇到原开发离职、Bug 长期无人修复、接口不稳定、性能下降、代码难以接手等问题,可以联系我做一次远程技术排查。
适合以下情况:
✅ 老旧 PHP 系统无人维护
✅ Laravel / Yii2 项目 Bug 修复
✅ 后台管理系统小功能迭代
✅ RESTful API 接口排查
✅ MySQL / Redis / Nginx 性能问题
✅ 长期远程兼职维护
可先从一次小问题开始:
✅ 线上报错排查
✅ 接口异常分析
✅ 慢查询与性能瓶颈定位
✅ 代码结构初步评估
✅ 部署环境与日志检查
如需咨询,请联系我,并注明:PHP 维护咨询。
联系方式:
Telegram:@shuijingwan
微信:13980074657
邮箱:shuijingwanwq@gmail.com

发表回复