Php yii2中带确认的删除按钮

Php yii2中带确认的删除按钮,php,yii,yii2,crud,Php,Yii,Yii2,Crud,此view.php是在Yii2中使用CRUD生成的,但删除按钮不确认窗口 但是在Yii2中使用CRUD生成的index.php中,delete的确认窗口起作用 <p> <?= Html::a('Edit', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> <?= Html::a('Delete', ['delete', 'id' => $mo

此view.php是在Yii2中使用CRUD生成的,但删除按钮不确认窗口

但是在Yii2中使用CRUD生成的index.php中,delete的确认窗口起作用

<p>
    <?= Html::a('Edit', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
    <?= Html::a('Delete', ['delete', 'id' => $model->id], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => 'Are you sure you want to delete this item?',
                'method' => 'post',
            ],
    ]) ?>
    <?= Html::a('Back','index', ['class' => 'btn btn-warning']) ?>
</p>

index.php中的删除按钮:

<a href="var/delete?id=2" title="Delete" aria-label="Delete" data-pjax="0" data-confirm="Are you sure you want to delete this item?" data-method="post"><span class="glyphicon glyphicon-trash"></span></a>

在view.php中删除按钮:

<a class="btn btn-danger" href="var/delete?id=2" data-confirm="Are you sure you want to delete this item?" data-method="post">Delete</a>

测试仍在进行中

要获得确认的默认支持,您应该注册

使用

或者(不推荐,仅举个例子)


那么您的意思是index.php delete正在显示确认,但这个没有?如果是,那么检查两个按钮的实际html,您会发现一些差异。克服了这个差异,这个也能工作。我添加了代码差异,但不起作用。我认为对于JS文件,在view.php中有没有包含来自yii的JS文件。你有一些Javascript错误吗?因为很明显js确认不起作用。请检查你的控制台。
use yii\web\YiiAsset;
YiiAsset::register($this);
$this->registerJsFile('@yii/assets/yii.js', ['depends' => [\yii\web\JqueryAsset::className()]]);