zelax90 / zf-user-notification
基于事件的用户通知系统
Requires
Suggests
- xelax90/zf-mail-config: Convenient configuration for zend-mail transport
This package is auto-updated.
Last update: 2024-09-20 01:06:35 UTC
README
此模块提供了一个基于事件和简单的用户通知系统。
安装
使用composer安装XelaxUserNotification。有关composer文档,请参阅 getcomposer.org。
composer require xelax90/zf-user-notification
然后在您的 config/application.config.php
中添加 XelaxUserNotification
,并运行doctrine模式更新以创建数据库表。
php vendor/bin/doctrine-module orm:schema-tool:update --force
现在将提供的配置文件 vendor/xelax90/zf-user-notification/config/xelax-user-notification.global.php
和 vendor/xelax90/zf-user-notification/config/xelax-user-notification.local.php.dist
复制到您的 config/autoload
目录。同时,将 xelax-user-notification.local.php.dist
文件复制一份,但不包含 .dist
扩展名。
配置
要发送电子邮件通知,请将您的邮件服务器配置在 config/autoload/xelax-user-module.local.php
文件中。
您可以使用 config/autoload/xelax-user-module.global.php
中的全局配置来修改电子邮件模板和其他全局设置。配置文件内对每个设置都有文档说明。
发送通知
要发送通知,从服务管理器获取 XelaxUserNotification\Service\Notification
服务实例,并调用其中一个函数 sendSystemNotification
(用于系统到用户的通知),sendUserNotification
(用于用户到用户的通知)。这些函数创建一个 NotificationInterface
实例并触发相应的事件,以便任何通知处理程序都可以处理创建的通知。要发送自定义事件和通知,请使用 sendNotification
方法。
处理通知
要处理通知,只需创建一个监听器来监听来自 XelaxUserNotification\Service\Notification
类的事件。有两种默认事件,即 Notification::EVENT_SYSTEM_NOTIFICATION
和 Notification::EVENT_USER_NOTIFICATION
,分别用于两种不同的通知类型。在实现额外逻辑之前,您可能需要查看一些默认通知处理程序。
渲染和邮件处理程序
RenderAndMailHandler
使用模板引擎渲染通知,然后使用邮件传输将通知发送给接收者。默认情况下,它使用 Zend\View\Renderer\PhpRenderer
模板引擎和 Zend\Mail\Transport\TransportInterface
服务作为传输。可以使用 xelax90/zf-mail-config
模块注册传输服务。
您可以在您的应用程序或模块配置中配置模板。全局配置文件中提供了一些文档。配置的电子邮件模板将通过 MvcTranslator
传递以获取本地化模板名称,然后传递给模板引擎(请参阅 language/en_US.php
和 language/de_DE.php
)。