0

不多说, 直接上代码吗 Yii2.0.7

以下是view.php视图文件

<?php
use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model app\models\Setting */

$this->title = $model->name;

?>
<div class="setting-view">

    <h1><?= Html::encode($this->title) ?></h1>

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

其中Yii::t('app','Update') 是翻译用的, Update -> '更新',

$model 来自控制器,

问题是confirm弹出框未正常弹出, 以下代码

     'data' => [
            'confirm' => 'Are you sure you want to delete this item?',
            'method' => 'post',
        ],
 生成HTML代码如下
 <a class="btn btn-danger" href="/setting/delete?id=11" data-confirm="Are you sure you want to delete this item?" data-method="post">删除</a>    
 
 虽然生成HTML, 但是感觉并没有得到执行. 
 坐等高人指点.~ ~      

1个回答

0

是不是有js报错了,或者没有加载 yii.js

撰写答案