Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • SensioLabs Professional services to help you with Symfony
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by
  1. Home
  2. Documentation
  3. Bundles
  4. SonataAdminBundle
  5. Installation

Installation

Edit this page

SonataAdminBundle can be installed at any moment during a project's lifecycle.

Download the Bundle

1
composer require sonata-project/admin-bundle

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:

  • SonataDoctrineORMAdminBundle (integrates the Doctrine ORM);
  • SonataDoctrineMongoDBAdminBundle (integrates the Doctrine MongoDB ODM);

You can download them in the same way as the SonataAdminBundle. Please, choose one and follow its installation instructions before proceeding.

Note

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

Enable the Bundle

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

1
2
3
4
5
6
7
8
9
10
11
12
// config/bundles.php

return [
    // ...
    Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
    Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true],
    Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true],
    Sonata\AdminBundle\SonataAdminBundle::class => ['all' => true],
    Sonata\Doctrine\Bridge\Symfony\SonataDoctrineBundle::class => ['all' => true],
    Sonata\Form\Bridge\Symfony\SonataFormBundle::class => ['all' => true],
    Sonata\Twig\Bridge\Symfony\SonataTwigBundle::class => ['all' => true],
];

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 have to tell the block bundle about the existence of the admin block:

1
2
3
4
5
6
7
# config/packages/sonata_admin.yaml

sonata_block:
    blocks:
        # enable the SonataAdminBundle block
        sonata.admin.block.admin_list:
            contexts: [admin]

Note

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.

Enable the "translator" service

The translator service is required by SonataAdmin to display all labels properly. For more information: https://symfony.com/doc/5.4/translation.html#configuration

1
2
3
4
# config/packages/framework.yaml

framework:
    translator: { fallbacks: ['%locale%'] }

Define routes

The bundles are now registered and configured correctly. To be able to access SonataAdminBundle's pages, the Symfony router needs to know the routes provided by the SonataAdminBundle. You can do this by adding its routes to your application's routing file:

1
2
3
4
5
6
7
8
9
10
# config/routes/sonata_admin.yaml

admin_area:
    resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
    prefix: /admin

_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /admin

Note

If you're using XML or PHP to specify your application's configuration, the above routing configuration must be placed in routing.xml or routing.php according to your format (i.e. XML or PHP).

Note

For those curious about the resource: . setting: it is unusual syntax but used because Symfony requires a resource to be defined (which points to a real file). Once this validation passes Sonata's AdminPoolLoader is in charge of processing this route and it ignores the resource setting.

At this point you can already access the (empty) admin dashboard by visiting the URL: http://yoursite.local/admin/dashboard.

Preparing your Environment

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

1
2
bin/console cache:clear
bin/console assets:install

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

Note

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

Sonata Dashboard

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.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    Take the exam at home

    Take the exam at home

    No stress: we've got you covered with our 116 automated quality checks of your code

    No stress: we've got you covered with our 116 automated quality checks of your code

    Version:

    Table of Contents

    • Download the Bundle
    • Download a Storage Bundle
    • Enable the Bundle
    • Configure the Installed Bundles
    • Enable the "translator" service
    • Define routes
    • Preparing your Environment
    • The Admin Interface

    Symfony footer

    Avatar of Tristan Maindron, a Symfony contributor

    Thanks Tristan Maindron (@tmaindron) for being a Symfony contributor

    2 commits • 149 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • What is Symfony?
      • Symfony at a Glance
      • Symfony Components
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • Symfony Community
      • SymfonyConnect
      • Events & Meetups
      • Projects using Symfony
      • Contributors
      • Symfony Jobs
      • Backers
      • Code of Conduct
      • Downloads Stats
      • Support
    • Blog

      • All Blog Posts
      • A Week of Symfony
      • Case Studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Living on the edge
      • Releases
      • Security Advisories
      • Symfony Insight
      • Twig
      • SensioLabs Blog
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Powered by

    Follow Symfony