在yii2中确认删除按钮

时间:2017-05-31 20:29:58

标签: php yii yii2 crud

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

但是在Yii2中使用CRUD生成的index.php中,删除的确认窗口有效。

<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>

1 个答案:

答案 0 :(得分:0)

section about yii.js仍在进行中。

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

使用yii\web\YiiAsset

use yii\web\YiiAsset;
YiiAsset::register($this);

registering script files(不推荐,仅举例)

$this->registerJsFile('@yii/assets/yii.js', ['depends' => [\yii\web\JqueryAsset::className()]]);