Sonata with Symfony3.4 - 依赖注入(正确的Sonata管理服务声明)

问题描述 投票:2回答:1

我正在尝试在我的symphony 3.4项目上安装Sonata(sonata-project / admin-bundle)。

不幸的是,当我添加我的第一个服务时,我发现了一个错误。

services.yaml:

    admin.carrier:
    class: App\Admin\CarrierAdmin
    arguments: [~, App\Entity\Carrier, ~]
    tags:
        - { name: sonata.admin, manager_type: orm, label: Carrier }
    public: true

我访问http://localhost/admin/dashboard时得到的错误:

1) FatalThrowableError

Type error: strlen() expects parameter 1 to be string, null given
in AddDependencyCallsCompilerPass.php (line 401)
at strlen(null)in AddDependencyCallsCompilerPass.php (line 401)
at AddDependencyCallsCompilerPass->replaceDefaultArguments(array('admin.carrier', 'SonataAdminBundle:CRUD'), object(Definition), null)in AddDependencyCallsCompilerPass.php (line 67)
at AddDependencyCallsCompilerPass->process(object(ContainerBuilder))in Compiler.php (line 141)
at Compiler->compile(object(ContainerBuilder))in ContainerBuilder.php (line 753)
at ContainerBuilder->compile()in Kernel.php (line 634)
at Kernel->initializeContainer()in Kernel.php (line 137)
at Kernel->boot()in Kernel.php (line 197)
at Kernel->handle(object(Request))in index.php (line 25)

有人能帮帮我吗?

symfony dependency-injection sonata-admin symfony-sonata symfony-3.4
1个回答
1
投票

首先,为您的管理服务添加应用前缀是个好主意。但你在CRUD控制器声明中的错误。第三个参数 - 是此管理服务的CRUD控制器。因此,您应该使用默认值:SonataAdminBundle:CRUD

app.admin.carrier:
    class: App\Admin\CarrierAdmin
    arguments: [~, App\Entity\Carrier, SonataAdminBundle:CRUD]
    tags:
        - { name: sonata.admin, manager_type: orm, group: 'carrier', label_catalogue: "admin", label: 'carrier' }
© www.soinside.com 2019 - 2024. All rights reserved.