[英]Pass two entities in one Form
I have a little question: When I want to build Forms with the createForm()
function. 我有一个小问题:当我想使用
createForm()
函数构建Forms时。 How I can add a second entity to this? 我如何在其中添加第二个实体?
Here is my example code. 这是我的示例代码。
public function newAction()
{
$entity = new Event();
$picture = new Picture();
$form = $this->createForm(new EventType(), $entity);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
});
I tried the add function on $form
, but it doesn't work. 我在
$form
上尝试了add函数,但是它不起作用。 Now I will add the Entity Fields from Picture to the form I created before. 现在,我将“图片”中的“实体字段”添加到之前创建的表单中。 Thank for your help.
谢谢您帮忙。
The correct way to handle your situtation whould be using subforms / field-types. 处理子态的正确方法应该使用子表单/字段类型。
Create a form EventPictureType
and add EventType
and PictureType
to it. 创建一个窗体
EventPictureType
并向其中添加EventType
和PictureType
。
See the cookbook chapter Embedded Forms & How to Create a Custom Form Field Type . 参见食谱手册“ 嵌入式表单”和“ 如何创建自定义表单字段类型” 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.