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

时间:2017-12-21 08:59:49

标签: symfony dependency-injection sonata-admin symfony-sonata symfony-3.4

我试图在我的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)

有人可以帮助我吗?

1 个答案:

答案 0 :(得分: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' }