我想问一下如何在奏鸣曲管理员中创建多级子级?我有一个与同一类有 childSection 关系的 Section 类。我怎么能遇到section可以有childSection而childSection可以有另一个childSection等的情况...
这是我的实体类:
class Section
{
/**
* @ORM\ManyToOne(targetEntity=Section::class, inversedBy="childrenSection")
*/
private $parentSection;
/**
* @ORM\OneToMany(targetEntity=Section::class, mappedBy="parentSection")
*/
private $childrenSection;
}
服务.yaml
admin.section:
class: App\Admin\SectionAdmin
arguments: [~, App\Entity\Section, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Section }
calls:
- [addChild, ['@admin.section', 'parentSection']]
public: true
管理类:
SectionAdmin.php
final class SectionAdmin extends AbstractAdmin
{
protected function configureRoutes(RouteCollection $collection)
{
$collection
->add('parentSection', $this->getRouterIdParameter() . '/section/list');
}
protected function configureListFields(ListMapper $listMapper): void
{
$listMapper
->add('id')
->add('name')
->add('_action', null, [
'actions' => [
'edit' => [],
'delete' => [],
'parentSection' => ['template' => 'BUTTON LIST SECTION FILE'],
],
]);
}
}
我面临以下错误:
检测到服务“admin.section”的循环引用,路径:“admin.section -> admin.section”。
有什么方法可以在不限制奏鸣曲管理中的孩子深度的情况下创建孩子吗?