Symfony 2 Form collection field with type file

前端 未结 4 885
悲&欢浪女
悲&欢浪女 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:32

    You need to specify the type of the widget in collection

    Look at the: http://symfony.com/doc/2.0/reference/forms/types/collection.html

    $builder->add('pictures', 'collection', array(
      // each item in the array will be an "email" field
      'type'   => 'file',
      // these options are passed to each "email" type
      'options'  => array(
        'required'  => false,
      ),
    ));
    

    For further reading I suggest

    http://symfony.com/doc/2.0/reference/forms/types/file.html

    Also you need to add sth to this collection to display cuz it will be empty when initialize like in your constructor of entity.

提交回复
热议问题