This version of the bundle requires Symfony 2.7+.
Warning : For now only Doctrine ORM is supported
$ 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(),
// ...
);
}
The goal of this bundle is to make one or many entities notifiables
.
- Use the
@Notifiable
annotation on your entity - 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.
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
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
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.
Go to basic usage