szmnmichalowski / szm-notification
用于在会话中存储通知的控制器插件。用于通知视图助手
1.0.0
2017-03-25 14:51 UTC
Requires
- php: ^5.6 || ^7.0
- zendframework/zend-session: ^2.5
Requires (Dev)
- phpunit/phpunit: ^4.8 || ^5.0
- zendframework/zend-mvc: ^3.0
This package is not auto-updated.
Last update: 2024-09-28 20:14:47 UTC
README
SzmNotification 是一个 Zend Framework 2/3 控制器插件,用于在会话容器中存储通知(与 FlashMessanger 相同)。它旨在与以下通知助手之一一起使用
- SzmNoty - jQuery 插件 http://ned.im/noty/
安装
您可以通过 composer 安装此模块
1. 将此项目添加到您的 composer.json 中
"require": {
"szmnmichalowski/szm-notification": "dev-master"
}
2. 更新您的依赖项
$ php composer.phar update
3. 将模块添加到您的 application.config.php 中。它需要 Zend\Session
return array(
'modules' => array(
'Zend\Session',
'SzmNotification' // <- Add this line
)
);
用法
此插件默认定义了 4 种通知类型
- info
- success
- warning
- error
但也可以添加自定义类型的通知
如何使用它
使用示例
$this->notification()->add('info', 'Lorem ipsum');
$this->notification()->has('info');
$this->notification()->get('info');
$this->notification()->addInfo('Lorem ipsum');
$this->notification()->hasInfo();
$this->notification()->getInfo();
可用方法
全局方法
add($type, $text)
- 添加通知has($type)
- 检查命名空间中是否包含在先前的请求中添加的任何通知hasCurrent($type)
- 检查命名空间中是否包含在当前请求期间添加的任何通知get($type)
- 返回先前的请求中的通知getCurrent($type)
- 返回当前请求中的通知getAll()
- 返回先前的请求中的所有通知getAllCurrent()
- 返回当前请求中的所有通知
以下方法对每种类型(包括自定义类型)都可用。只需将 *
替换为通知类型
add*($text)
- 添加通知has*()
- 检查命名空间中是否包含在先前的请求中添加的任何通知hasCurrent*()
- 检查命名空间中是否包含在当前请求期间添加的任何通知get*()
- 返回先前的请求中的通知getCurrent*()
- 返回当前请求中的通知
示例
$this-notification()->addCustomType('This is custom type notification');
$this-notification()->addFoo('This is custom type notification');
$this-notification()->addBar('This is custom type notification');
$this-notification()->getCustomType();
$this-notification()->getFoo();
$this-notification()->getCurrentBar();