Documentation » Admin

2. Creating an Admin »

« Admin Bundle

1. Installation

SonataAdminBundle is just a bundle and as such, you can install it at any moment during a project’s lifecycle.

1.1. 1. Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require sonata-project/admin-bundle "2.3.*"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

1.2. 1.1. Download a Storage Bundle

You’ve now downloaded the SonataAdminBundle. While this bundle contains all functionality, it needs storage bundles to be able to communicate with a database. Before using the SonataAdminBundle, you have to download one of these storage bundles. The official storage bundles are:

You can download them in the same way as the SonataAdminBundle. For instance, to download the SonataDoctrineORMAdminBundle, execute the following command:

$ composer require sonata-project/doctrine-orm-admin-bundle "2.3.*"


Don’t know which to choose? Most new users prefer SonataDoctrineORMAdmin, to interact with traditional relational databases (MySQL, PostgreSQL, etc).

1.3. Step 2: Enable the Bundle

Then, enable the bundle and the bundles is relies on by adding the following line in the app/AppKernel.php file of your project:

// app/AppKernel.php

// ...
class AppKernel extends Kernel
    public function registerBundles()
        $bundles = array(
            // ...

            // The admin requires some twig functions defined in the security
            // bundle, like is_granted. Register this bundle if it wasn't the case
            // already.
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),

            // These are the other bundles the SonataAdminBundle relies on
            new Sonata\CoreBundle\SonataCoreBundle(),
            new Sonata\BlockBundle\SonataBlockBundle(),
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),

            // And finally, the storage and SonataAdminBundle
            new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
            new Sonata\AdminBundle\SonataAdminBundle(),

        // ...

    // ...


If a bundle is already registered somewhere in your AppKernel.php, you should not register it again.


Since version 2.3, the bundle comes with jQuery and other front-end libraries. To update the versions (which isn’t required), you can use Bower. To make sure you get the dependencies that match the version of SonataAdminBundle you are using, you can make bower use the local bower dependency file, like this:

$ bower install ./vendor/sonata-project/admin-bundle/bower.json

1.4. Step 3: Configure the Installed Bundles

Now all needed bundles are downloaded and registered, you have to add some configuration. The admin interface is using SonataBlockBundle to put everything in blocks. You just have to tell the block bundle about the existence of the admin block:

# app/config/config.yml
    default_contexts: [cms]
        # enable the SonataAdminBundle block
            contexts: [admin]
        # ...


Don’t worry too much if, at this point, you don’t yet understand fully what a block is. The SonataBlockBundle is a useful tool, but it’s not vital that you understand it in order to use the admin bundle.

1.5. Step 4: Import Routing Configuration

The bundles are now registered and configured correctly. Before you can use it, the Symfony router needs to know the routes provided by the SonataAdminBundle. You can do this by importing them in the routing configuration:

# app/config/routing.yml
    resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
    prefix: /admin

1.6. Step 5: Preparing your Environment

As with all bundles you install, it’s a good practice to clear the cache and install the assets:

$ php app/console cache:clear
$ php app/console assets:install

1.7. The Admin Interface

You’ve finished the installation process, congratulations. If you fire up the server, you can now visit the admin page on http://localhost:8000/admin


This tutorial assumes you are using the build-in server using the php app/console server:start (or server:run) command.


As you can see, the admin panel is very empty. This is because no bundle has provided admin functionality for the admin bundle yet. Fortunately, you’ll learn how to do this in the next chapter.

Found a typo? Something is wrong in this documentation? Just fork and edit it!