danvick / yii2-sweetalert2
Alert widget based on SweetAlert2 extension {@link https://sweetalert2.github.io/)
Installs: 30
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 1
Type:yii2-extension
Requires
- php: >=7
- npm-asset/sweetalert2: 11.7.3
- yiisoft/yii2: *
- yiisoft/yii2-bootstrap4: @dev
Requires (Dev)
- friendsofphp/php-cs-fixer: ~2.0
- phpunit/phpunit: ^7.0
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2025-04-18 12:27:46 UTC
README
Yii2 Sweet Alert2 Widget
Alert widget based on SweetAlert2
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist danvick/yii2-sweetalert2 "*"
or add
"danvick/yii2-sweetalert2": "*"
to the require section of your composer.json.
Usage
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 danvick\sweetalert2\SweetAlert::widget();
For render the custom message you can use the following code:
// A replacement for the "prompt" function echo \danvick\yii2-sweetalert2\SweetAlert::widget([ 'type' => \danvick\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' => [ 'danvick\yii2-sweetalert2\SweetAlertAsset' => [ 'overrideConfirm' => false ] ] ]
Sweet Alert2 Options
You can find them on the sweetalert2 homepage