Skip to content

Latest commit

 

History

History
executable file
·
152 lines (94 loc) · 3.23 KB

index.rst

File metadata and controls

executable file
·
152 lines (94 loc) · 3.23 KB

MgiletNotificationBundle

A simple Symfony 3 bundle for user notifications

Installation

Prerequisites

This version of the bundle requires Symfony 2.7+.

Warning : For now only Doctrine ORM is supported

Basic installation:

Require the bundle with composer:

$ composer require mgilet/notification-bundle

Composer will install the bundle to your project's vendor/mgilet/notification-bundle directory.

Then add the following line in the AppKernel.php:

<?php
// app/AppKernel.php

public function registerBundles()
{
   $bundles = array(
       // ...
       new Mgilet\NotificationBundle\MgiletNotificationBundle(),
       // ...
   );
}

Configure notifiables classes:

The goal of this bundle is to make one or many entities notifiables.

  1. Use the @Notifiable annotation on your entity
  2. Implement the Mgilet\NotificationBundle\NotifiableInterface interface (it's an empty interface)

And that's it !

Example:

<?php
// src/AppBundle/Entity/MyEntity.php

namespace AppBundle\Entity;

...
use Mgilet\NotificationBundle\Annotation\Notifiable;
use Mgilet\NotificationBundle\NotifiableInterface;

/**
 * @ORM\Entity
 * @ORM\Table(name="my_entity")
 * @Notifiable(name="my_entity")
 */
class MyEntity implements NotifiableInterface
{
    ...

You can set as many entities notifiables as you want. Entities with multiple identifiers are supported.

After this, you can send notifications to any notifiable entity.

Update Doctrine

To finish the installation, don't forget to update your schema:

Symfony 2.x

$ php app/console doctrine:schema:update --force

Symfony 3.x

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

Enable the Notification controller :

This bundle provides a controller named NotificationController, which is used to do basic operations (mark as seen, display all...)

In order to enable the controller, simply put this in your routing.yml :

# routing.yml

mgilet_notifications:
    resource: "@MgiletNotificationBundle/Controller/"
    prefix: /notifications

Translations (optionnal)

If you wish to use default texts provided in this bundle, you have to make sure you have translator enabled in your config.

# app/config/config.yml

framework:
    translator: ~

For more information about translations, check Symfony documentation.

Basic usage :

Go to basic usage