วันศุกร์ที่ 23 ธันวาคม พ.ศ. 2565

yii2 sweet alert

 *** ใช้ได้กับ theme มากับ Yii (Layout main)
AppAsset.php

namespace app\assets;

use yii\web\AssetBundle;

/**
 * Main application asset bundle.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/site.css',
        'css/style.css',
    ];
    public $js = [
        'js/yii-override.js',
    ];
    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset',
        ######
        'app\assets\SweetAlertAsset',
    ];
}

SweetAlertAsset.php

<?php

namespace app\assets;

class SweetAlertAsset extends \yii\web\AssetBundle
{
    public $sourcePath = '@bower/sweetalert/dist';
    public $css = [
        'sweetalert.css',
    ] ;
    public $js  = [
        'sweetalert.min.js'
    ];
}

Folder:::  web/js/yii-override.js

 yii.confirm = function (message, okCallback, cancelCallback) {
    swal({
        title: message,
        type: 'warning',
        showCancelButton: true,
        closeOnConfirm: true,
        allowOutsideClick: true
    }, okCallback);
};

ถ้าเป็น Theme Adminlte   เข้าไปแก้ไขที่
***theme/adminlte/layout/content.php

//use dmstr\widgets\Alert;
use yii2mod\alert\Alert;


นำไปใส่ Controller Create Update

Yii::$app->session->setFlash('info', 'แก้ไขข้อมูล เรียบร้อยแล้ว');
 return $this->redirect(['view', 'id' => $model->driver_id])



วันอังคารที่ 20 ธันวาคม พ.ศ. 2565