Sonata Admin:不存在的服务 "security.authorization_checker"

Sonata Admin: non-existent service "security.authorization_checker"

我正在尝试使用 Sonata Admin Bundle 设置一个简单的 CMS。我使用 composer 将 sonata-project/admin-bundlesonata-project/doctrine-orm-admin-bundle 添加到一个空的 git 存储库,然后按照 https://sonata-project.org/bundles/admin/3-x/doc/getting_started/installation.html

上的其余说明进行操作

现在我访问 http://localhost/admin/dashboard,说明上说应该给我一个空白的仪表板。相反,我得到一个 ServiceNotFoundException,说明:

The service "sonata.admin.menu.group_provider" has a dependency on a non-existent service "security.authorization_checker".

是否有我需要 install/add 的捆绑软件或配置才能解决此问题?

===

当我 运行 bin/console debug:container security.authorization_checker 我得到以下输出:

In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:

The service "sonata.admin.menu.group_provider" has a dependency on a non-existent service "secur ity.authorization_checker".

===

这里是config/packages/sonata_admin.yaml:

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

... 这里是 config/services.yaml:

parameters:
    locale: 'en'

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

    # add more service definitions when explicit configuration is needed
    # please note that last definitions always *replace* previous ones

... 这是我的 bundles.php:

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
    Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
    Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
    Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
    Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
    Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
    Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
    Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle::class => ['all' => true],
    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],
];

您需要安装 symfony 安全。如果您还没有 flex,也许还可以。

composer require symfony/flex
composer require security

这将自动为您安装和配置包。