SonataAdmin安装问题

时间:2017-06-14 11:44:11

标签: symfony sonata-admin symfony-sonata symfony-3.2

我尝试在我的Symfony项目上安装SonataAdmin,但在文档的第2部分结束时,当我试图继续“http://localhost:8000/admin/”时出现错误:“你有请求一个不存在的服务“admin.category”。(从“C:\ wamp64 \ www \ Sonata / app / config \ routing.yml”导入)。确保有一个支持“sonata_admin”的加载程序型“。

我不知道为什么,我给我所有的参数代码也许它可以帮助你理解我的问题。

参数:     #parameter_name:value

服务:

# default configuration for services in *this* file
_defaults:
    # automatically injects dependencies in your services
    autowire: true
    # automatically registers your services as commands, event subscribers, etc.
    autoconfigure: true
    # this means you cannot fetch services directly from the container via $container->get()
    # if you need to do this, you can override this setting on individual services
    public: false

admin.category:
    class: AppBundle\Admin\CategoryAdmin
    arguments: [~, AppBundle\Entity\Category, ~]
    tags:
        - { name: sonata.admin, manager_type: orm, label: Category }


# makes classes in src/AppBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
AppBundle\:
    resource: '../../src/AppBundle/*'
    # you can exclude directories or files
    # but if a service is unused, it's removed anyway
    exclude: '../../src/AppBundle/{Entity,Repository,Tests}'

# controllers are imported separately to make sure they're public
# and have a tag that allows actions to type-hint services
AppBundle\Controller\:
    resource: '../../src/AppBundle/Controller'
    public: true
    tags: ['controller.service_arguments']

# add more services, or override services that need manual wiring
# AppBundle\Service\ExampleService:
#     arguments:
#         $someArgument: 'some_value'

`

缩进是错误的我给你添加了这个文件的图片。 Service code

3 个答案:

答案 0 :(得分:1)

奏鸣曲管理服务必须是公开的。在您的配置中,您的默认值为public: false,这就是您收到此错误的原因。

所以你有两个选择:

  1. 为您的管理服务指定public: true(在您的示例文件中)
  2. 或者更好的方法:创建一个新的服务文件(例如admin.yml),你不使用这些默认值(_defaults密钥和public: false)。默认情况下,公开为true,因此您不必按_defaults指定。在这种情况下,您必须在config.yml中导入新文件才能正常工作:
  3. app/config.yml

    的顶部
    imports:
        - { resource: parameters.yml }
        - { resource: security.yml }
        - { resource: services.yml }
        - { resource: admin.yml }
    

    app/admin.yml内容:

    services:
        admin.category:
            class: AppBundle\Admin\CategoryAdmin
            arguments: [~, AppBundle\Entity\Category, ~]
            tags:
                - { name: sonata.admin, manager_type: orm, label: Category }
    

答案 1 :(得分:0)

我认为您通过在{Sonata / app / config / routing.yml中编写RawSecurityDescriptor服务而犯了一个错误, 而不是 Sonata / src / YourAdminBundle / Resources / config / services.yml

答案 2 :(得分:0)

在终端上运行此命令。因为您可能错过了安装

php composer.phar require sonata-project/doctrine-orm-admin-bundle

After This将以下代码添加到AppKernel.php

// app / AppKernel.php

public function registerBundles()
{
    return array(
        // ...
        // set up basic sonata requirements
        // ...
        new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
        // ...
    );
}