lesha724 / yii2-notification
yii2 中的通知
v0.0.4
2018-01-05 10:58 UTC
Requires
- bower-asset/sweetalert: ~1.1.0
- yiisoft/yii2: *
- yiisoft/yii2-bootstrap: *
README
yii2 中的通知: bootstrap alerts、sweet alerts、noty
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist lesha724/yii2-notification "*"
或将以下内容添加到您的 composer.json 文件的 require 部分:
"lesha724/yii2-notification": "*"
Bootstrap Alerts
扩展安装完成后,只需在代码中使用它即可
- 在 action 中设置消息,例如
<?php Yii::$app->session->setFlash('bootstrap-success', 'This is the message'); ?>
- 将小部件添加到页面上的方法如下
<?= \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
闪存消息小部件
- 在 action 中设置消息,例如
<?php Yii::$app->session->setFlash('sweeat-alert-success', 'This is the message'); ?>
- 将小部件添加到页面上的方法如下
<?= \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 ], ], ]); ?>
简单小部件
<?php $function = <<<JS function(isConfirm){ if (isConfirm) { swal("Deleted!", "Your imaginary file has been deleted.", "success"); } else { swal("Cancelled", "Your imaginary file is safe :)", "error"); } } JS; echo \lesha724\Notification\widgets\SimpleSweetAlert::widget([ 'options'=>[ //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 ] ]) ?>