Get Sweet Alerts to work with Yii2 easily without bower or npm

The bower package of Sweet Alert forces you to use webpack. You’ll see errors with “require null” or something like that.

Instead I found a hack to install sweet alert and still use it as a javascript function instead of a PHP widget.

Step 1 - Use the Yii2 package

Install this package using composer.



Step 2 - Instead of the widget add the asset manager, that aryelds already made for you.

use aryelds\sweetalert\SweetAlertAsset;

SweetAlertAsset::register($this);


Step 3 - Add it into your js

swal("Oh NO", "You have a error!", "error");  
2 Likes