gfh151 / yii2-通知
Yii2 通知模块
v0.0.1
2016-05-23 14:08 UTC
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-08-28 22:22:12 UTC
README
Yii2 通知模块
此模块提供向用户发送通知的功能。实现了管理部分,您可以在其中查看消息和创建项目。在前端,消息将在 bootstrap 警报框中显示。通过计时器小部件从后端请求新消息并显示。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令
php composer.phar require --prefer-dist fgh151/yii2-noifications "*"
或将以下内容添加到您的 composer.json 文件的 require 部分。
"fgh151/yii2-noifications": "*"
使用方法
扩展安装完成后,只需在您的代码中使用它来配置
'modules' => [ ... 'notification' => [ 'class' => 'fgh151\notifications\Module' ] ]
然后在模块将出现的页面上包含小部件
echo fgh151\notifications\widgets\notifications\Widget::widget();
API
您可以直接创建消息,例如
$notify = new fgh151\notifications\models\Notification(); $notify->Message = $message; $notify->UserId = $user; $notify->Type = $type; $notify->save();
或者您可以使用 send 方法
fgh151\notifications\models\Notification::send('info', 'Info message' , 127);
其中第一个参数是 bootstrap 消息类型,第二个参数是消息文本,第三个参数是接收者用户 ID,您也可以发送用户数组,例如
fgh151\notifications\models\Notification::send('info', 'Info message' , [1,2,3,4,5]);