首页 新闻 搜索 专区 学院

Yii自带的confirm, 未弹出弹框, 直接走后面的代码了, 怎么回事?

0
悬赏园豆:100 [已解决问题] 解决于 2017-11-27 13:18

不多说, 直接上代码吗 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, 但是感觉并没有得到执行. 
 坐等高人指点.~ ~      
Eternity味道的主页 Eternity味道 | 初学一级 | 园豆:60
提问于:2017-10-25 19:13
< >
分享
最佳答案
0
<?= Html::a('删除', ['post/delete', 'id' => $post['id']],['data-confirm'=>'确定要删除吗?']) ?>
<?= Html::a('Do Something', ['my-action', 'id' => $id], [
    'class' => 'btn btn-primary',
    'data' => [
        'confirm' => 'Are you sure you want to do?',
        'method' => 'post',
    ],
]) ?>
收获园豆:100
悟行 | 专家六级 |园豆:12240 | 2017-10-26 09:21
其他回答(1)
0

原因是yii.js未自动引入, 去asset里面设置一下
以下是我的appasset.php文件配置

 

class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ 'css/site.css', 'static/css/tabs.css', ]; public $js = [ '/static/js/jquery-migrate.js', '/static/js/AdminLTE.min.js', ]; public $depends = [ 'yii\web\YiiAsset', 'yii\web\JqueryAsset', 'yii\bootstrap\BootstrapAsset', 'backend\assets\AdminLTEAsset' ]; }

Eternity味道 | 园豆:60 (初学一级) | 2017-11-27 13:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册