Symfony 2 Embedded forms using one to many db relationship

狂风中的少年 提交于 2019-12-03 07:27:35

Oh I faced the same problem, but I found the solution, hope this will help you :-)

You're forgetting to add an Address object to the member entity.

In your action you'll need to do the following:

$member = new Member();
$member->addAddress(new Address());

$form = $this->createForm(new MemberType(), $member);

And then in your template:

 {% for address in form.address %}
  {{ form_widget(address.firstLine) }}
 {% endfor %}

Btw your 'firstline' widget doesn't relate to an entity property.

Btw if you called addAddress two times, you would of course get two 'firstline' widgets in your form.

Hope this works. best of luck.

Llewellyn, do you mean something like thid:

public function editAction($id) { $em = $this->getDoctrine()->getManager();

    $entity = $em->getRepository('imBundle:Inspecciones')->find($id);

    $entity_valores = $em->getRepository('imBundle:ValoresInspecciones')->findByInspecciones($id);

    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Inspecciones entity.');
    }

    $entity->setValoresInspecciones($entity_valores);



    $editForm = $this->createEditForm($entity);
    $deleteForm = $this->createDeleteForm($id);

    return $this->render('imBundle:Inspecciones:edit.html.twig', array(
        'entity'      => $entity,
        'edit_form'   => $editForm->createView(),
        'delete_form' => $deleteForm->createView(),
    ));
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!