tasmaniski/zf2-flash-noty-messenger

此包的最新版本(2.0.2)没有可用的许可信息。

美丽的 JS 通知视图辅助工具。

2.0.2 2017-04-13 13:11 UTC

This package is not auto-updated.

Last update: 2024-09-20 19:40:29 UTC


README

新版本已发布!当前版本支持 Zend Framework 3

使用 NOTY jQuery 插件显示 flash 消息的视图辅助工具。http://ned.im/noty/#/about
您必须包含 jQuery 和 Bootstrap 的最新版本。

alt tag

安装

在 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 样式。