用于Zend Framework 2/3的通知jQuery插件

1.0.0 2017-03-25 16:14 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:56:03 UTC


README

Software License Build Status Code Coverage

SzmNoty是一个集成jQyert Noty插件,用于渲染来自SzmNotification控制器插件的Zend Framework 2/3视图助手的通知。

Notifications

安装

您可以通过composer安装此模块

1. 将此项目添加到您的composer.json中

"require": {
    "szmnmichalowski/szm-noty": "dev-master"
}

2. 更新您的依赖项

$ php composer.phar update

3. 将模块添加到您的application.config.php中。

return array(
    'modules' => array(
        'Zend\Session',
        'SzmNotification' // <- Add this line
        'SzmNoty' // <- Add this line
    )
);

配置

szm-noty/config/noty.local.php.dist文件复制到根目录的config/autoload,并重命名为noty.local.php(移除.dist扩展名)配置文件应如下所示

return [
    'notifications' => [
        'library_url' => 'https://cdnjs.cloudflare.com/ajax/libs/jquery-noty/2.4.1/packaged/jquery.noty.packaged.min.js',
        'default_options' => [
            'timeout' => 3000,
            'callback' => [
                'afterShow' => 'function() {
                    console.log("Test!")
                }'
            ]
        ],
        'types' => [
            'info' => [
                'type' => 'info',
            ],
            'success' => [
                'type' => 'success',
                'timeout' => 6000,
            ],
            'warning' => [
                'type' => 'warning'
            ],
            'error' => [
                'type' => 'error'
            ],
        ],
    ]
];

default_options - 所有类型通知的选项。types - 特定类型通知的选项(success可能具有与error不同的选项)

您可以在http://ned.im/noty/options.html上找到完整的选项列表

使用方法

如果您需要有关如何在控制器中添加通知的详细信息,请访问SzmNotification模块。

在控制器中

    public function indexAction()
    {
        $this->notification()->add('info', 'This is info');
        $this->notification()->add('success', 'This is success');
        $this->notification()->add('warning', 'This is warning');
        $this->notification()->add('error', 'This is error');
        ...
    }

然后在您的布局或视图中

<?= $this->notification()->setIncludeLibrary(true)->renderCurrent(); ?>

结果,您应该会看到与上图相同的通知

可用方法

可用方法的列表

  • setIncludeLibrary() - 如果true,则将附加到noty库的链接。如果您未手动添加库路径,则使用它。默认为false
  • render(string $type = null, $options = []) - 从之前的请求中渲染通知。如果没有提供参数,则显示配置文件中提供的所有通知选项
  • renderCurrent(string $type = null, $options = []) - 与上述方法相同,只有一个区别。它渲染在本次请求期间添加的通知。