jimmytournemaine/notification-bundle

此包已被废弃且不再维护。未建议替代包。

通知系统集成

dev-master 2016-09-05 22:39 UTC

This package is not auto-updated.

Last update: 2020-12-25 23:02:21 UTC


README

#安装

SensioLabsInsight

##步骤 1:下载 Bundle

打开命令行,进入您的项目目录,并执行以下命令以下载此 Bundle 的最新稳定版本

$ composer require jimmytournemaine/notification-bundle "master"

此命令要求您全局安装 Composer,具体请参阅 Composer 文档中的安装章节

##步骤 2:启用 Bundle

然后,通过将其添加到项目 app/AppKernel.php 文件中注册的 Bundle 列表中来启用此 Bundle

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new JT\NotificationBundle\NotificationBundle(),
        );

        // ...
    }

    // ...
}
```

##步骤 3:路由

# app/config/routing.yml

jt_notification:
    resource: "@JTNotificationBundle/Resources/config/routing.yml"

##步骤 4:链接您的用户实体

# app/config/config.yml

doctrine:
    orm:
        resolve_target_entities:
            JT\NotificationBundle\Model\NotifyableInterface: AppBundle\Entity\User

步骤 5:更新您的数据库

php bin/console doctrine:schema:update --force

创建您的通知类型

<?php
namespace AppBundle\Notification\Type;

use JT\NotificationBundle\Builder\NotificationBuilderInterface;
use JT\NotificationBundle\Notification\Type\AbstractType;

class PostType extends AbstractType
{

    public function buildNotification(NotificationBuilderInterface $builder, array $options)
    {
        $builder
            ->addIcon('bell', array(
                'type' => 'icon',
                'prefix' => 'fa',
                'alt' => '+'
            ))
            ->addTitle('notification.post.title', array(
                'trans_parameters' => array('%name%' => 'Jimmy')
            ))
            ->addDescription('notification.post.description', array(
                'trans_domain' => "MyDomain"
            ))
            ->addLink('homepage', array(
                'type' => 'route'
            ))
            ->addUsers($options['users'])
        ;
    }
}

#发送您的通知

$this->get('jt_notification.helper')->send(PostType::class, $options, $users);

#显示用户的通知

{% if is_granted('IS_AUTHENTICATED_REMEMBERED') %}
    {{ jt_notification_render() }}
{% endif %}

#覆盖渲染

您可以通过覆盖 JTNotification::macros.html.twig 来编辑通知的渲染,具体请参阅Symfony 文档