sonata_type_collection : 从当前实体实例设置默认字段值
sonata_type_collection : set default field value from current entity instance
我需要有关“sonata_type_collection”的帮助:有没有办法定义默认值(此处:现有实体的实例) 用于“sonata_type_collection”特定字段?
或者也许是给他参数的方法?
让我澄清一下:
这是我实际的“sonata_type_collection”表单渲染后的屏幕截图:
有没有办法让“Machine”字段保存我正在编辑的“MachineInfo”实体的当前实例单击(最后一个)“添加”按钮时出现“无选择”文本?
这是我当前来自“MachineInfoAdmin”的“configureFormFields”:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', 'text', array('label' => 'Nom'))
->add('description', 'text', array('label' => 'Description'))
->add('internalReference', 'text', array('label' => 'Référence interne'))
;
//Already instantiated
if ($this->id($this->getSubject())) {
$formMapper
->add(
'machineParts',
'sonata_type_collection',
array(
'label' => "Pièces",
),
array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
)
)
;
}
}
我很纠结那个,希望有大神指教,帮助我m(_ _)m
我找到了解决办法,而且很简单,我很惭愧=__="
我忘记在新实例化的 MachinePart
中设置对 MachineInfo 的引用
public function addMachinePart(MachinePartsInfo $machineParts) {
$machineParts->setMachineInfo($this); //Missed this line
$this->machineParts[] = $machineParts;
return $this;
}
我希望这对以后的人有所帮助:)
我需要有关“sonata_type_collection”的帮助:有没有办法定义默认值(此处:现有实体的实例) 用于“sonata_type_collection”特定字段? 或者也许是给他参数的方法?
让我澄清一下: 这是我实际的“sonata_type_collection”表单渲染后的屏幕截图:
有没有办法让“Machine”字段保存我正在编辑的“MachineInfo”实体的当前实例单击(最后一个)“添加”按钮时出现“无选择”文本?
这是我当前来自“MachineInfoAdmin”的“configureFormFields”:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', 'text', array('label' => 'Nom'))
->add('description', 'text', array('label' => 'Description'))
->add('internalReference', 'text', array('label' => 'Référence interne'))
;
//Already instantiated
if ($this->id($this->getSubject())) {
$formMapper
->add(
'machineParts',
'sonata_type_collection',
array(
'label' => "Pièces",
),
array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
)
)
;
}
}
我很纠结那个,希望有大神指教,帮助我m(_ _)m
我找到了解决办法,而且很简单,我很惭愧=__=" 我忘记在新实例化的 MachinePart
中设置对 MachineInfo 的引用public function addMachinePart(MachinePartsInfo $machineParts) {
$machineParts->setMachineInfo($this); //Missed this line
$this->machineParts[] = $machineParts;
return $this;
}
我希望这对以后的人有所帮助:)