Symfony 2 Embedded forms using one to many db relationship

前端 未结 2 2115
鱼传尺愫
鱼传尺愫 2021-02-09 06:17

I\'m have a problem embedding forms from different entities in one form, my form is being displayed with firstname [input] lastname [input] address - but the address has no inpu

2条回答
  •  爱一瞬间的悲伤
    2021-02-09 07:16

    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.

提交回复
热议问题