Symfony 2 Form collection field with type file

前端 未结 4 874
悲&欢浪女
悲&欢浪女 2021-02-19 09:49

I want to upload multiple files with POST request (without Ajax). Can I use Symfony 2\'s form collection field with type file like this:

Code in Entity:



        
4条回答
  •  我寻月下人不归
    2021-02-19 10:07

    To actually render input types you will need to set the allow_add option in the collection to true and use the form prototype of the collection, javascript and a button to add file fields.

    An example based in the documentation (Collection- adding and removing)

    The form:

    {# ... #} {# store the prototype on the data-prototype attribute #}
      {% for imageField in form.images%}
    • {{ form_widget(imageField) }}
    • {% endfor %}
    Add image

    The script:

    
    

    This is just an idea, there is still plenty to do depending on your needs. If this wasn't what you were looking for, maybe you could call the add button click as a workaround.

提交回复
热议问题