Install Sonata

Install Sonata


To speed up the installation, all composer are used with –no update option. composer update is only used at the end of the installation to get all bundles in once.

Get Sonata

Make sure composer is updated

# sudo /usr/local/bin/composer self-update

Get Sonata Bundle

# composer require sonata-project/admin-bundle --no-update

Get ORM Bundle

# composer require sonata-project/doctrine-orm-admin-bundle --no-update

Get SonataBlockBundle

# composer require sonata-project/block-bundle --no-update

Get KnpMenuBundle

# composer require knplabs/knp-menu-bundle --no-update

Install Bundles

Now you can install bundles with composer:

# composer update

KnpMenuBundle config

Add in app/config/config.yml

# app/config/config.yml
    twig:  # use "twig: false" to disable the Twig extension and the TwigRenderer
        template: knp_menu.html.twig
    templating: false # if true, enables the helper for PHP templates
    default_renderer: twig # The renderer to use, list is also available by default

Enable Admin

Add in app/config/config.yml:

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

Don’t forget to enable SonataAdminBundle too:

// app/AppKernel.php
public function registerBundles()
    return array(
        // ...
        // Add Sonata dependencies
        new Sonata\CoreBundle\SonataCoreBundle(),
        new Sonata\BlockBundle\SonataBlockBundle(),
        new Knp\Bundle\MenuBundle\KnpMenuBundle(),
        // Uses SonataDoctrineORMAdmin
        new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
        // Then add SonataAdminBundle
        new Sonata\AdminBundle\SonataAdminBundle(),
        // ...

Install the asset from bundle

# php app/console assets:install web

Delete the cache

# php app/console cache:clear

Create Admin File

in /src/Acme/AdminBundle/, create Admin directory

in /src/Acme/AdminBundle/Admin, create PostAdmin.php, with:

namespace Acme\AdminBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;

 * Post
class PostAdmin extends Admin

Install Sonata admin

add its routes to your application’s routing file

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

    resource: .
    type: sonata_admin
    prefix: /admin

Create either a new admin.xml file inside the Acme/AdminBundle/Resources/config/ folder:

<!-- Acme/AdminBundle/Resources/config/admin.xml -->
<container xmlns=""
       <service id="" class="Acme\AdminBundle\Admin\PostAdmin">
          <tag name="sonata.admin" manager_type="orm" group="Content" label="Post"/>
          <argument />
          <argument />
          <call method="setTranslationDomain">

Include your new configuration file in the main config.yml

# app/config/config.yml
    - { resource: @AcmeAdminBundle/Resources/config/admin.xml }

Install Easyextends

# composer require sonata-project/easy-extends-bundle --no-update

Composer update

# composer update

Enable EasyExtendsBundle


// app/AppKernel.php

public function registerBundles()
    return array(
        // ...
        new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
        // ...

Enable search

Enable simple search in sonata admin is easy, just add in app/config/config.yml:

         search:              SonataAdminBundle:Core:search.html.twig            
         search_result_block: SonataAdminBundle:Block:block_search_result.html.twig
      default_contexts: [cms]                                                     
              contexts: [admin]

But it may be difficult to use if you have a lot data in your Database

Raphaël has written 45 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>