Simplifies doing controllers as services

Installs: 20 690

Dependents: 0

Suggesters: 0

Stars: 13

Watchers: 2

Forks: 3

Open Issues: 1

Type: symfony-bundle

v0.2.1 2013-10-30 12:29 UTC


So, you decided to define your controllers as services? That's great! But isn't injecting the same basic services into each controllers tedious and boring? Not anymore!

The abstract controller of this bundle is automatically injected with the following commonly used services:

  • form.factory,
  • router,
  • translator,
  • security.context,
  • session, and
  • templating.

It also provides a couple of helper methods:

  • getUser() — to get the currently logged in user;
  • addFlash($type, $message) — to add a flash message to the session.


  1. Add this to composer.json:

        "require": {
            "elnur/abstract-controller-bundle": "dev-master"

    And run:

    composer update elnur/abstract-controller-bundle
  2. Enable the bundle in app/AppKernel.php:

    public function registerBundles()
        $bundles = array(
            // ...
            new Elnur\AbstractControllerBundle\ElnurAbstractControllerBundle(),


Make your controller extend the AbstractController class:

namespace Acme\Bundle\AppBundle\Controller;

use Elnur\AbstractControllerBundle\AbstractController;

class UserController extends AbstractController
    // ...

And define elnur.controller.abstract as the parent service:

        class: Acme\Bundle\AppBundle\Controller\UserController
        parent: elnur.controller.abstract


This bundle is under the MIT license. See the complete license in the bundle: