简体   繁体   English

无法在Sonata Admin Bundle中使工作孩子成为admin

[英]Can't make work child admin in sonata admin bundle

I have a simple relation model in my project, I have requests and comments and created admins classes for both entities. 我的项目中有一个简单的关系模型,我有请求和注释,并为两个实体创建了admins类。 They works just fine as separate admins, and all relations works fine on a public part of the project, but I can't set up comments as a child admin class for requests. 他们可以作为单独的管理员正常工作,并且所有关系在项目的公共部分都可以正常工作,但是我不能将注释设置为子管理员类来处理请求。

here is what I have in services.yaml 这是我在services.yaml中拥有的

admin.maintenanceRequest:
        class: App\Admin\MaintenanceRequestAdmin
        arguments: [~, App\Entity\MaintenanceRequest ,~]
        tags:
            - {name: sonata.admin, manager_type: orm, label: Maintenance }
        public: true
        calls:
            - [ addChild, ['@App\Admin\MaintenanceCommentAdmin', 'maintenance_request_id']]

I also defined $parentAssociationMapping in my child admin class: 我还在子管理类中定义了$ parentAssociationMapping:

protected $parentAssociationMapping = 'maintenance_request_id';

But it leads to this error: 但这会导致此错误:

Cannot autowire service "App\\Admin\\MaintenanceCommentAdmin": argument "$code" of method "Sonata\\AdminBundle\\Admin\\AbstractAdmin::__construct()" has no type-hint, you should configure its value explicitly. 无法自动装配服务“ App \\ Admin \\ MaintenanceCommentAdmin”:方法“ Sonata \\ AdminBundle \\ Admin \\ AbstractAdmin :: __ construct()”的参数“ $ code”没有类型提示,您应该显式配置其值。

I tried to find solution on my own for quite a while, but seems like no one have problem with that. 我试图寻找自己的解决方案已经有一段时间了,但似乎没人对此有问题。 Hope someone can help me, Im really new to sonata and coding in general, any help would be greatly appreciated. 希望有人能帮助我,我真的很喜欢奏鸣曲和编码,任何帮助将不胜感激。 I'll provide any additional info if it's required. 如果需要的话,我会提供其他信息。

I just found a solution: change your 我刚刚找到了解决方案:更改您的

    - [ addChild, ['@App\Admin\MaintenanceCommentAdmin', 'maintenance_request_id']]

with

    - [ addChild, ['@admin.maintenanceComment', 'maintenance_request_id']]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM