Getting started with Symfony 2.3 + Sonata Admin / User Bundles

The following tutorial is my process for getting up and running with an ACL-secured Symfony 2.3 + Sonata User and Admin bundle configuration.

Please note: I am assuming you have a clean, new symfony project all ready to go. If you've already started development, you will need to use some common sense and merge some of my stuff with yours. If you do have a clean project, then you can just copy the following code straight over the relevant files.

Step 1.

Make sure you have PHP set up in your environment, and composer.phar in your project's root or available on your path. This is outside the scope of this post, and there are plenty of resources on Google to help with your specific environment.

Step 2.

Set up your /composer.json (in the root of your project) with all the necessary dependencies. You can use this one I prepared earlier:

Step 3.


> composer update

And wait for it to finish. Assuming there are no errors, we can continue.

Step 4.

Overwrite your app/AppKernel.php file with the following pastebin. Make sure you comment out line 26 (new Application\Sonata\UserBundle\ApplicationSonataUserBundle()) as we don't need it until later.

Step 5: Overwrite settings.

These files should get you started:

app/config/config.yml -

app/config/routing.yml -

app/config/security.yml -

Step 6: Generate Sonata User Bundle.

Execute the following from the root of your project:

> php app/console sonata:easy-extends:generate SonataUserBundle

And move the generated app/Application folder to src/Application

Step 7: Uncomment that line.

Remember Step 4? Uncomment line 26 (new Application\Sonata\UserBundle\ApplicationSonataUserBundle()) of app/AppKernel.php because we need it now.

Step 8: Set up an admin user.

> php app/console fos:user:create admin [email protected]

Step 9: Set up the schema.

If you haven't already, create the schema:

> php app/console doctrine:schema:create

Alternatively, if you already have a schema set up, run instead:

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

Step 10: Set up your ACL's.

> app/console init:acl
> app/console sonata:admin:setup-acl
> app/console sonata:admin:generate-object-acl

Note: You need to run the last command whenever you set up new entityadmin mappings.

Step 11: Install the assets.

> app/console assets:install

Step 12: Clear the cache.

> app/console cache:clear
> app/console cache:warmup

Step 13: Check out your handywork.

Open up your websites /admin/dashboard path. For me it's:


Step 14: Map some admin classes.

Beyond the scope of this tutorial, but also the entire point of this bundle, is that you will want to set up some entities then map them to the admin panel. Check out this page for a great tutorial on how to do that:

Step through each section of the tutorial, I found it to be extremely helpful in getting my own entities into the admin interface.

Good luck!