Notifiaction in yii2
Notifiaction in yii2:
bootstrap alerts,
sweet alerts,
noty, (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist lesha724/yii2-notification "*"
or add, (*4)
"lesha724/yii2-notification": "*"
to the require section of your composer.json
file., (*5)
Bootstrap Alerts
Once the extension is installed, simply use it in your code by :, (*6)
1) Set the message in your action, for example:, (*7)
<?php
Yii::$app->session->setFlash('bootstrap-success', 'This is the message');
?>
2) Simply add widget to your page as follows:, (*8)
<?= \lesha724\Notification\widgets\BootstrapAlert::widget([
'alertTypes' => [
'bootstrap-error' => [
'class' => 'alert-danger',
'icon' => '<i class="icon glyphicon glyphicon-ban-circle"></i>',
],
'bootstrap-danger' => [
'class' => 'alert-danger',
'icon' => '<i class="icon glyphicon glyphicon-ban-circle"></i>',
],
'bootstrap-success' => [
'class' => 'alert-success',
'icon' => '<i class="icon glyphicon glyphicon-ok"></i>',
],
'bootstrap-info' => [
'class' => 'alert-info',
'icon' => '<i class="icon glyphicon glyphicon-exclamation-sign"></i>',
],
'bootstrap-warning' => [
'class' => 'alert-warning',
'icon' => '<i class="icon glyphicon glyphicon-warning-sign"></i>',
],
],
'closeButton'=>[],
]); ?>
SweetAlerts
Widget for flash messages, (*9)
1) Set the message in your action, for example:, (*10)
<?php
Yii::$app->session->setFlash('sweeat-alert-success', 'This is the message');
?>
2) Simply add widget to your page as follows:, (*11)
<?= \lesha724\Notification\widgets\SweetAlert::widget([
'alertTypes' => [
'sweet-alert-error' => [
//you can use all options from http://t4t5.github.io/sweetalert/
'type' => 'error',
'title' => 'Error!',
/* function use example:
* function(isConfirm){
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
}
*/
'function' => null
],
'sweet-alert-success' => [
'type' => 'success',
'title' => 'Success!',
'function' => null
],
'sweet-alert-info' => [
'type' => 'info',
'title' => 'Info!',
'function' => null
],
'sweet-alert-warning' => [
'type' => 'warning',
'title' => 'Warning!',
'function' => null
],
],
]); ?>
Simple widget, (*12)
[
//you can use all options from http://t4t5.github.io/sweetalert/
'title'=> "Are you sure?",
'text'=> "You will not be able to recover this imaginary file!",
'type'=> "warning",
'showCancelButton'=> true,
'confirmButtonColor'=> "#DD6B55",
'confirmButtonText'=> "Yes, delete it!",
'cancelButtonText'=> "No, cancel plx!",
'closeOnConfirm'=> false,
'closeOnCancel'=> false,
'function'=>$function
]
]) ?>