我在symfony中有两个关系oneToMany,我想知道是否有在第一个实体(父)中添加自定义按钮以指向子项编辑页面。
如果需要,让我再解释一下。
当我在这个关系中设置sonata_type_collection时,我得到了内联编辑的子属性,这很棒。我遇到的问题是这个子实体 有另一个子类型sonata_type_collection和sonata管理员显示这个孩子的方式不是编辑它的最佳方式。所以,我正在考虑插入一个 在此处按钮以编辑此实体并查看其子实体。但我无法弄清楚如何做到这一点。
我尝试使用'按钮'用于实现此目的的类型,但是我收到以下错误:
选项" label_render"," property_path"," sonata_field_description"不存在。定义的选项包括:" attr"," auto_initialize"," block_name","禁用","标签",& #34; label_format"," translation_domain"。
任何人都知道如何做到这一点?
编辑1
我有3个关系oneToMany的课程:
让我们说“建立'”' SecEstablishment'和' FlatSecEstablishment'。企业可以拥有cero或更多的SecEstablishments,而SecEstablishment可以拥有一个或多个FlatSecEstablishments。希望这段代码有助于理解我需要做什么。
类EstablishmentControllerAdmin扩展了AbstractAdmin {
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->with('Details')
->add('id','text', array('label' => 'Id', 'disabled' => true))
->add('establishment', 'text', array ('label' => 'establishment'))
->add('address', 'text', array('label' => 'Address', 'required' => false))
->add('phone', 'text', array('label' => 'Phone', 'required' => false))
->add('postalCode', 'integer', array('label' => 'Postal Code', 'required' => false))
->end()
->with('Establishment sectors')
->add('sectores','sonata_type_collection',
array(
'btn_add' => 'New Sector',
'type_options' => array('delete' => false)
),
array(
'edit' => 'inline',
'inline' => 'table'
))
->end();
}
}
类SecEstablishmentControllerAdmin扩展AbstractAdmin {
protected $parentAssociationMapping = 'establishment';
protected function configureFormFields(FormMapper $formMapper) {
if($this->hasParentFieldDescription()) {
$formMapper
->with('Details')
->add('detSec', 'text')
->add('flatStructure', 'sonata_type_model', array(
'btn_list' => 'Select',
'btn_add' => false,
'btn_delete' => false,
'required' => false
), array(
'placeholder' => 'Select Flat Structure',
'nullable' => true,
))
->end();
} else {
$formMapper
->with('Details')
->add('flatStructure', 'sonata_type_model', array(
'btn_list' => 'Select',
'btn_add' => false,
'btn_delete' => false,
'required' => false
), array(
'placeholder' => 'Select Flat Structure',
'nullable' => true,
))
->add('secFlat','sonata_type_collection',
array(
'btn_add' => false,
'type_options' => array('delete' => false)
),
array(
'edit' => 'inline',
'inline' => 'table'
))
->end();
}
}
}
class FlatSecEstablishmentControllerAdmin扩展AbstractAdmin {
protected $parentAssociationMapping = 'secEstablishment';
protected function configureFormFields(FormMapper $formMapper) {
$formMapper
->with('Details')
->add('detFlat', 'text', array('label' => 'Flat Detail'))
->end();
}
}