rsol / yii2-alert
Yii-Framework widget for Flash Alerts
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- bower-asset/pnotify: *
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2025-01-04 19:37:35 UTC
README
Widget for add PNotify alerts in yii2 application
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist rsol/yii2-alert "*"
or add
"rsol/yii2-alert": "*"
to the require section of your composer.json
file.
Usage
in main layout:
use rsol\alert\widgets\Alert;
<?= Alert::widget() ?>
you can style your PNotify by
<?= Alert::widget([ 'style' => 'bootstrap3',//default ]) ?>
in any place of your code:
Yii::$app->session->addFlash('success', Yii::t('users', 'Added social networks connections'));
advanced
Yii::$app->session->addFlash('success', [ 'title' => Yii::t('users', 'Added social networks connections'), 'text' => Yii::t('users', 'Are you want to use photo from {soc} as profile photo?', [ 'soc' => $client->getTitle(), ]), 'addclass' => 'alert-styled-left alert-arrow-left text-sky-royal', 'hide' => false, 'confirm' => [ 'confirm' => true, 'buttons' => [ [ 'text' => Yii::t('users', 'YES'), 'addClass' => 'btn-sm', ], [ 'text' => Yii::t('users', 'NO'), 'addClass' => 'btn-sm', ] ] ], 'buttons' => [ 'closer' => false, 'sticker' => false, ], 'history' => [ 'history' => false, ], 'on' => [ 'pnotify.confirm' => "function() { $('.cropper').attr('src', '{$attributes['User']['photo']}'); $('#modal_large').modal('show'); }", ], ]);
or JS
$swal = [ 'title' => Yii::t('users', 'Added social networks connections'), 'text' => Yii::t('users', 'Are you want to use photo from {soc} as profile photo?', [ 'soc' => $client->getTitle(), ]), 'confirmButtonColor' => "#66BB6A", 'type' => "success", 'showCancelButton' => true, 'confirmButtonText' => Yii::t('users', 'YES'), 'cancelButtonText' => Yii::t('users', 'NO'), ]; $ajax = [ 'url' => Url::toRoute("/user/user/soc-image"), 'data' => [ 'soc' => $filed, ], 'success' => new JsExpression('function(data) { if (data.success) { $(".col-lg-3 .eg-preview img.img-circle").attr("src", data.src); $("li.dropdown.dropdown-user a.dropdown-toggle img.img-circle").attr("src", data.src); } }'), 'dataType' => "json", ]; Yii::$app->session->addFlash('js', 'swal(' . Json::encode($swal) . ', function(isConfirm){ if (isConfirm) { $.ajax(' . Json::encode($ajax) . '); } });');