izemize / yii2-noty
Yii小部件,用于Noty jQuery通知插件
v1.0.1
2016-01-10 09:21 UTC
Requires
- bower-asset/noty: ^2.3
- yiisoft/yii2: 2.0.6
This package is not auto-updated.
Last update: 2024-09-20 19:40:18 UTC
README
Yii2小部件,用于Noty jQuery通知插件,访问Noty
对于Yii1:请检查yii-noty
安装
安装此扩展的首选方法是通过composer
注意:以下说明针对全局composer安装。您可能需要将
composer
替换为您的设置中的phpcomposer.phar
(或类似)。
直接安装
composer require shifrin/yii2-noty 1.0.1
或将它手动添加到composer.json
中,然后更新composer
"shifrin/yii2-noty": "1.0.1",
composer update
使用说明
将小部件添加到主布局文件中,如下所示:
\shifrin\noty\NotyWidget::widget([
'options' => [ // you can add js options here, see noty plugin page for available options
'dismissQueue' => true,
'layout' => 'topCenter',
'theme' => 'relax',
'animation' => [
'open' => 'animated flipInX',
'close' => 'animated flipOutX',
],
'timeout' => false
],
'enableSessionFlash' => true
'enableIcon' => true,
'registerAnimateCss' => true,
'registerButtonsCss' => true,
'registerFontAwesomeCss' => true,
]);
此小部件将创建一个JS函数Noty()
,因此它将全局可用,您可以在自定义JS代码中调用此函数。请参阅以下示例。
var n = Noty('id');
$.noty.setText(n.options.id, 'Welcome to our site!');
$.noty.setType(n.options.id, 'information');
您可以在控制器中或需要的地方设置闪存消息,例如这样。然而,如果您将enableSessionFlash
设置为false
,则它将不受影响。
\Yii::$app->session->setFlash('type', 'Message here');
将type
替换为可用的类型
可用类型
- success
- error
- warning
- information
- alert