ruroNize/zend-flash-noty-messenger

此包的最新版本(3.0.0)没有提供许可证信息。

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

3.0.0 2019-02-20 06:14 UTC

This package is auto-updated.

Last update: 2024-09-20 18:54:32 UTC


README

本版本支持Zend Framework 3和Noty v3

通过NOTY插件显示闪存消息的视图辅助工具 http://ned.im/noty/#/

Screenshot

安装

在composer.json文件中添加,然后运行composer update

{
  "require": {
    "rurounize/zend-flash-noty-messenger":"^3.0"
  }
}

该模块应在Zend Framework 3的config/modules.config.php中进行注册

return [
    // ...
    'FlashNotyMessenger'
    // ...
]

注意 FlashNotyMessenger包含本地文件和CDN资源,您可以选择使用哪些。

之后,从vendor/rurounize/zend-flash-noty-messenger/asset/复制JS文件
并将其放在路径public/js/noty/

mkdir public/js/noty/
# For develop
cp vendor/rurounize/zend-flash-noty-messenger/asset/noty.js public/js/noty/noty.js
# For production
cp vendor/rurounize/zend-flash-noty-messenger/asset/noty.min.js public/js/noty/noty.min.js

如果您可以使用本地资源,则从vendor/rurounize/zend-flash-noty-messenger/asset/复制CSS文件
并将其放在路径public/css/noty/

mkdir public/css/noty/
# For develop
cp vendor/rurounize/zend-flash-noty-messenger/asset/noty.css public/css/noty/noty.css
# For production
cp vendor/rurounize/zend-flash-noty-messenger/asset/noty.min.css public/css/noty/noty.min.css

如果您想自定义配置,可以在config/autoload/global.phpconfig/autoload/local.php中复制

return [
    // ...
    'noty_config' => [
        'layout'    => 'topRight',
        'theme'     => 'mint',
        'closeWith' => ['click', 'button'],
        /* 'animation' => [
            'open'  => 'animated fadeInRight',
            'close' => 'animated fadeOutRight'
        ] */
    ],

    'noty_assets' => [
        'use'   => 'cdn', // local for local assets
        'cdn'   => [
            'css'   => 'https://cdnjs.cloudflare.com/ajax/libs/noty/3.1.4/noty.min.css',
            'js'    => 'https://cdnjs.cloudflare.com/ajax/libs/noty/3.1.4/noty.min.js',
        ],
        'local' => [
            'css'   => 'css/noty/noty.min.css',
            'js'    => 'js/noty/noty.min.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 -->
<?= $this->inlineScript() ?>

使用

在任何控制器中使用它。
在控制器中添加消息,消息将被显示(在重定向请求或当前请求中)

<?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/tasmaniski/zend-flash-noty-messenger