kamran377 / yii2-sweetalert2
基于 SweetAlert2 扩展的 Alert 小部件 {@link https://sweetalert2.github.io/)
2.1.0
2024-03-07 16:59 UTC
Requires
- php: >=7
- npm-asset/sweetalert2: 11.7.3
- yiisoft/yii2: *
- yiisoft/yii2-bootstrap5: @dev
Requires (Dev)
- friendsofphp/php-cs-fixer: ~2.0
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-09-07 18:09:27 UTC
README
Yii2 Sweet Alert2 小部件
基于 SweetAlert2 的 Alert 小部件
安装
安装此扩展的首选方式是通过 composer.
运行以下命令之一
php composer.phar require --prefer-dist kamran377/yii2-sweetalert2 "*"
或者将以下内容添加到你的 composer.json 文件的 require 部分中。
"kamran377/yii2-sweetalert2": "*"
使用方法
要渲染来自会话闪存的消息,可以使用以下代码
- 在动作中设置消息,例如
Yii::$app->session->setFlash('success', 'This is the message');
- 只需将小部件添加到页面中,如下所示
echo kamran377\sweetalert2\SweetAlert::widget();
要渲染自定义消息,可以使用以下代码
// A replacement for the "prompt" function echo \kamran377\yii2-sweetalert2\SweetAlert::widget([ 'type' => \kamran377\yii2-sweetalert2\SweetAlert::TYPE_WARNING, 'options' => [ 'title' => 'Oops...', 'text' => 'Something went wrong!', 'footer' => '<a href>Why do I have this issue?</a>' ] ]);
** JavaScript 确认对话框覆盖**
默认情况下,覆盖了原生的 JavaScript 确认对话框。要禁用此覆盖,请在 config.php 或 web.php(在高级模板中)中使用以下配置
'assetManager' => [ 'bundles' => [ 'kamran377\yii2-sweetalert2\SweetAlertAsset' => [ 'overrideConfirm' => false ] ] ]
Sweet Alert2 选项
你可以在 sweetalert2 主页 上找到它们。