Install and configure Symfony 2 and Sonata bundle

I found some bugs and inconsistencies while trying to install those 3 bundles by the book, so I decide to create that small tutorial.

What we gonna install:

  • Symfony Framework
  • SonataAdminBundle
  • SonataDoctrineORMAdminBundle
  • SonataEasyExtendsBundle

First we start by installing the Symfony Framework
[cce_bash]
composer create-project symfony/framework-standard-edition
[/cce_bash]

Now we jump to the sonata bundle
[cce_bash]
composer require sonata-project/admin-bundle
[/cce_bash]

Choose one connection, I use mysql so I need to install the SonataDoctrineORMAdminBundle
[cce_bash]
composer require sonata-project/doctrine-orm-admin-bundle
[/cce_bash]

Activate the bundles

SonataAdminBundle

AppKernel.php
[cce_php]
/* Sonata */
new SymfonyBundleSecurityBundleSecurityBundle(),
new SonataCoreBundleSonataCoreBundle(),
new SonataBlockBundleSonataBlockBundle(),
new KnpBundleMenuBundleKnpMenuBundle(),
new SonataDoctrineORMAdminBundleSonataDoctrineORMAdminBundle(),
new SonataAdminBundleSonataAdminBundle(),
[/cce_php]

config.yml
[cce_yaml]
sonata_block:
default_contexts: [cms]
blocks:
# Enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
[/cce_yaml]

routing.yml
[cce_yaml]
admin:
resource: ‘@SonataAdminBundle/Resources/config/routing/sonata_admin.xml’
prefix: /admin

_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
[/cce_yaml]

With this done, you should see a layout like this one in your site.

Sonata admin dashboard

At this moment we have the Sonata Admin Bundle configured in our site. We gonna process now with the Easy Extend Bundle then we end with the User Bundle.

EasyExtendBundle

Pretty simple to configure this bundle, start to download the bundle and activate the bundle in the AppKernel file.

[cce_bash]
php require sonata-project/easy-extends-bundle
[/cce_bash]

AppKernel.yml
[cce_php]
new SonataEasyExtendsBundleSonataEasyExtendsBundle(),
[/cce_php]

Leave a Reply