詹姆斯I / 通知包
为您的用户创建一个邮件和现场通知/警报系统
v0.1.0
2014-11-20 18:00 UTC
Requires
- symfony/framework-bundle: >=2.1
This package is auto-updated.
Last update: 2024-09-10 11:28:14 UTC
README
此Symfony包允许为网站的注册成员创建一个通知系统。类似于Facebook等网站上看到的那样。
通知对应于网站上发生的事件,用户应该被告知。通知类包含构建将要发送给用户的警报和电子邮件所需的视图的逻辑。
警报是现场通知 - 您应该在网站上实现一个部分,让用户可以看到他们的警报历史记录,并且可能让他们始终看到未查看的警报数量。
当提供通知时,通知器可以触发电子邮件和/或警报,具体取决于用户的偏好(必须通过NotifiableInterface实现)。
用法
- 将包添加到您的composer.json(注意:此包尚未达到稳定版本)
{ "require": { "jamesi/notification-bundle": "dev-master" } }
- 将包添加到您的AppKernel
public function registerBundles() { $bundles = array( ... new Jamesi\NotificationBundle\JamesiNotificationBundle(), }
- 让您的用户类实现
NotifiableInterface
public function getNotificationName() { // Who should the email be addressed to? return $this->getUsername(); } public function getNotificationEmail() { // Who should the email be addressed to? return $this->getEmail(); } public function acceptsNotificationAlert($type) { // Implement logic here for which on-site alerts the user wants return true; } public function acceptsNotificationEmail($type) { // Implement logic here for unsubscribing from types of email notification return true; }
- 创建一个扩展提供的警报实体实体,为其提供一个ID和实体类型(即您的用户实现)用于$ user多对一关系
<?php namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Jamesi\NotificationBundle\Entity\Alert as BaseAlert; /** * @ORM\Entity * @ORM\Table(name="alert") */ class Alert extends BaseAlert { /** * @var int * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @var User * @ORM\ManyToOne(targetEntity="User") */ protected $user; }
- 在
app/config/config.yml中配置包
jamesi_notification: alert_class: AppBundle\Entity\Alert from_email: address: myapp@example.com sender_name: My App Name
-
在您的包中开始创建通知子类(例如,参见
FooNotification) -
在您的控制器中,使用
jamesi_notification.notifier服务(Notifier类的一个实例)来发送通知,使用notify方法。