diecoding / yii2-toastr
为Yii2提供的简单闪现通知
v1.4.0
2024-05-20 17:01 UTC
Requires
- php: >=7.4.0
- npm-asset/toastr: ~2.1
- yiisoft/yii2: ~2.0
Requires (Dev)
- phpunit/phpunit: ~9.5.0
README
为Yii2提供的简单闪现通知
Yii2 Toastr 使用 Toastr
演示: https://codeseven.github.io/toastr/demo.html
目录
安装
此包可在 Packagist 上找到,您可以使用 Composer 进行安装。
composer require diecoding/yii2-toastr "^1.0"
或者将其添加到您的 composer.json
文件的 require 部分。
"diecoding/yii2-toastr": "^1.0"
依赖关系
- PHP 7.4+
- yiisoft/yii2
- npm-asset/toastr
使用方法
布局/视图
将
ToastrFlash
添加到您的布局或视图文件中,例如在文件views\layouts\main.php
中
布局/视图简单使用
use diecoding\toastr\ToastrFlash; ToastrFlash::widget();
布局/视图高级使用
use diecoding\toastr\ToastrFlash; ToastrFlash::widget([ "typeDefault" => ToastrFlash::TYPE_INFO, // (string) default `ToastrFlash::TYPE_INFO` "titleDefault" => "", // (string) default `""` "messageDefault" => "", // (string) default `""` "closeButton" => false, // (bool) default `false` "debug" => false, // (bool) default `false` "newestOnTop" => true, // (bool) default `true` "progressBar" => true, // (bool) default `true` "positionClass" => ToastrFlash::POSITION_TOP_RIGHT, // (string) default `ToastrFlash::POSITION_TOP_RIGHT` "preventDuplicates" => true, // (bool) default `true` "showDuration" => 300, // (int|null) default `300` in `ms`, `null` for skip "hideDuration" => 1000, // (int|null) default `1000` in `ms`, `null` for skip "timeOut" => 5000, // (int|null) default `5000` in `ms`, `null` for skip "extendedTimeOut" => 1000, // (int|null) default `1000` in `ms`, `null` for skip "showEasing" => "swing", // (string) default `swing`, `swing` and `linear` are built into jQuery "hideEasing" => "swing", // (string) default `swing`, `swing` and `linear` are built into jQuery "showMethod" => "slideDown", // (string) default `slideDown`, `fadeIn`, `slideDown`, and `show` are built into jQuery "hideMethod" => "slideUp", // (string) default `slideUp`, `hide`, `fadeOut` and `slideUp` are built into jQuery "tapToDismiss" => true, // (bool) default `true` "escapeHtml" => true, // (bool) default `true` "rtl" => false, // (bool) default `false` "skipCoreAssets" => false, // (bool) default `false`, `true` if use custom or external toastr assets "options" => [], // (array) default `[]`, Custom Toastr options and override default options ]);
控制器
只需像通常的警告一样使用
Yii::$app->session->setFlash($type, $message)
控制器简单使用
Yii::$app->session->setFlash('error', 'Message');
或者如果要在同一会话中使用多个闪现
Yii::$app->session->setFlash('error', [(string) 'Message 1', (string) 'Message 2', (string) 'Message 3']);
控制器高级使用(< v1.4.0)
Yii::$app->session->setFlash('error', [[(string) 'Title', (string) 'Message']]);
或者如果要在同一会话中使用多个闪现
Yii::$app->session->setFlash('error', [['Title 1', 'Message 1'], ['Title 2', 'Message 2'], ['Title 3', 'Message 3']]);
控制器高级使用(≥ v1.4.0)覆盖 Toastr 选项
Yii::$app->session->setFlash('error', [[(string) 'Title', (string) 'Message', (array) 'Options']]); // or Yii::$app->session->setFlash('error', [['title' => (string) 'Title', 'message' => (string) 'Message', 'options' => (array) 'Options']]);
或者如果要在同一会话中使用多个闪现
Yii::$app->session->setFlash('error', [ [ 'Title 1', 'Message 1', [ "progressBar" => true, "showDuration" => 300, "hideDuration" => 10000, "timeOut" => 5000, "extendedTimeOut" => 1000, ] ], [ 'title' => 'Title 2', 'message' => 'Message 2', 'options' => [ "progressBar" => false, "hideDuration" => 10000, ] ], ['Title 3', 'Message 3'], ['Message 4'], [ 'message' => 'Message 5', 'options' => [ "progressBar" => false, ] ], [ 'title' => 'Title 6', 'options' => [ "timeOut" => 50000, ] ], ]);
阅读更多文档:https://sugengsulistiyawan.my.id/docs/opensource/yii2/toastr/