Alert widget based on SweetAlert2
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist kamran377/yii2-sweetalert2 "*"
or add
"kamran377/yii2-sweetalert2": "*"
to the require section of your composer.json.
For render the message from session flash you can use the following code:
- Set the message in your action, for example:
Yii::$app->session->setFlash('success', 'This is the message');
- Simply add widget to your page as follows:
echo kamran377\sweetalert2\SweetAlert::widget();
For render the custom message you can use the following code:
// A replacement for the "prompt" function
echo \kamran377\yii2-sweetalert2\SweetAlert::widget([
'type' => \kamran377\yii2-sweetalert2\SweetAlert::TYPE_WARNING,
'options' => [
'title' => 'Oops...',
'text' => 'Something went wrong!',
'footer' => '<a href>Why do I have this issue?</a>'
]
]);
** Javascrip Confrim Dialog Override**
The native javascript confirm dialog is overridden by default, to disable this override, use the following configuration in config.php or web,php(in advanced template):
'assetManager' => [
'bundles' => [
'kamran377\yii2-sweetalert2\SweetAlertAsset' => [
'overrideConfirm' => false
]
]
]
You can find them on the sweetalert2 homepage