Setting up FOSMessageBundle
May 21, 2019 ยท View on GitHub
Step 1 - Requirements and Installing the bundle
Note FOSMessageBundle by default has a requirement for FOSUserBundle for some of its interfaces which can be swapped out if you're not using FOSUserBundle. See Using other UserBundles for more information.
The first step is to tell composer that you want to download FOSMessageBundle which can be achieved by typing the following at the command prompt:
Current
composer require friendsofsymfony/message-bundle
v1.3 (Legacy: Symfony 2, or <=3.3)
composer require friendsofsymfony/message-bundle:1.3.0
Step 2 - Setting up your user class
FOSMessageBundle requires that your user class implement ParticipantInterface. This
bundle does not have any direct dependencies to any particular UserBundle or
implementation of a user, except that it must implement the above interface.
Your user class may look something like the following:
<?php
// src/AppBundle/Entity/User.php
use Doctrine\ORM\Mapping as ORM;
use FOS\MessageBundle\Model\ParticipantInterface;
use FOS\UserBundle\Model\User as BaseUser;
/**
* @ORM\Entity
*/
class User extends BaseUser implements ParticipantInterface
{
}
Step 3 - Set up FOSMessageBundle's models
FOSMessageBundle has multiple models that must be implemented by you in an application bundle (that may or may not be a child of FOSMessageBundle).
We provide examples for both Mongo DB and ORM.
Step 4 - Enable the bundle in your kernel
The bundle must be added to your AppKernel.
Step usually not necescary in Symfony 4.
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new FOS\MessageBundle\FOSMessageBundle(),
// ...
);
}
Step 5 - Import the bundle routing
Add FOSMessageBundle's routing to your application with an optional routing prefix.
# app/config/routing.yml
fos_message:
resource: "@FOSMessageBundle/Resources/config/routing.xml"
prefix: /optional_routing_prefix
Step 6 - Check templating
Make sure to add this to framwork.yaml (and check twig is installed) if you run into the non-existant service templating issue:
templating:
engines:
twig
Installation Finished
At this point, the bundle has been installed and configured and should be ready for use. You can continue reading documentation by returning to the index.