Admin panel for Symfony from Sonata Bundle

4,624 Views

If you are looking for a quick solution for the administration panel for the Symfony framework, then I recommend you Sonata Admin Bundle. It is an administrative system in which you can easily build facilities for your project. In addition to the bundle of the administration panel, Stanta also provides other bundles such as: Block Bundle, Page Bundle (text pages), Newsl Blundle (news), Media Bundle (media management), Seo Bundle, Ecommerce (online store), Classification Bundle (categorization).

Installation and configuration of Sonata Admin Bundle for Symfony 4.

  1. Installation bundle form console:
composer require sonata-project/admin-bundle

2. Install one of the following Bundles for doctrinal management:

The standard is:

composer require sonata-project/doctrine-orm-admin-bundle

3. Go to the file configuration file: (config / bundles.php) and add the following entries:

// config/bundles.php

return [
    // ...
    Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
    Sonata\CoreBundle\SonataCoreBundle::class => ['all' => true],
    Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true],
    Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true],
    Sonata\AdminBundle\SonataAdminBundle::class => ['all' => true],
];

4. Create a file for routing in the location: (/ config / routes /) with the name: sonata_admin.yaml and the following content:

admin_area:
    resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
    prefix: /admin
 
_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /admin

5. Create a configuration file (Yaml) bundle in the location: (config / packages) named: sonata_admin.yaml with the following content. In the configuration file you will be able to manage the panel’s appearance (see documentation).

sonata_admin:
    title: 'Your Sonata Admin'
 
sonata_block:
    blocks:
        sonata.admin.block.admin_list:
            contexts: [admin]

6. At the end, follow the instructions below to clear the cache and install Assetic resources:

php bin/console cache:clear
php bin/console assets:install

Wonderfoul! Your adminpanel should be visible after starting the address: http://your_url/admin.

Fave fun!