tasmaniski / zend-flash-noty-messenger
此包的最新版本(2.0.2)没有提供许可信息。
美丽的 JS 通知的视图助手。
2.0.2
2017-04-13 13:11 UTC
Requires
- php: >=5.6
- zendframework/zend-mvc-plugin-flashmessenger: ^1.0
This package is auto-updated.
Last update: 2024-09-08 06:48:57 UTC
README
新版本已发布!当前版本支持 Zend Framework 3
使用 NOTY jQuery 插件显示 flash 信息的视图助手 http://ned.im/noty/#/about
必须包含 jQuery 和 Bootstrap 的最新版本。
安装
在 composer.json 文件中添加,然后运行 composer update
"require": { "tasmaniski/zend-flash-noty-messenger":"^2.0" }
该模块应在 config/application.config.php 中注册
'modules' => array( '...', 'FlashNotyMessenger' ),
之后,从 vendor/tasmaniski/zend-flash-noty-messenger/asset/
复制 2 个 JS 文件,并将其放置在路径 public/js/noty/
mkdir public/js/noty/ cp vendor/tasmaniski/zend-flash-noty-messenger/asset/jquery.noty.packaged.js public/js/noty/jquery.noty.packaged.js cp vendor/tasmaniski/zend-flash-noty-messenger/asset/jquery.noty.config.js public/js/noty/jquery.noty.config.js
设置
在 layout.phtml 的某个位置触发 fire()
/** * The fire() method do * Collect all messages from previous and current request * clear current messages because we will show it * add JS files * add JS notifications */ <?php $this->flashNoty()->fire(); ?> <!-- if you already don't have this line, must add it for including JS files --> <?php echo $this->inlineScript() ?>
我的代码示例
// at the end of layout.phtml /* fire all messages */ <?php $this->flashNoty()->fire(); ?> <!-- All Scripts to the bottom! --> <?php echo $this->inlineScript() // we call here inlineScript() ->appendFile($this->basePath('js/jquery.js')) ->appendFile($this->basePath('js/bootstrap.js')); ?>
注意:如果您想在 ZF2 应用中使用它,请在 composer.json 中添加 ^1.0 版本
使用
在任何控制器中使用它。
在您的控制器中添加消息,消息将被显示(在重定向请求或当前请求中)
<?php $this->flashMessenger()->addSuccessMessage('Success message, bravo!'); $this->flashMessenger()->addErrorMessage('Error with system, contact us.'); $this->flashMessenger()->addInfoMessage('Info message, to do whatever...'); $this->flashMessenger()->addWarningMessage('Warning message to be careful.');
致谢
我想感谢我的同事 https://github.com/maksi80 为通知的 CSS 样式。