title: How to create and render an array of objects in Symfony form
body: <p>Back when I was doing most of my code by hand I had a form that consisted of a variable number of div elements that I handled as an array via post upon submission, but I cannot for the life of me figure out how to do anything similar in Symfony and I'm starting to get really frustrated. Here's my original implementation of a template class for an object (with my own simple templating engine):</p>
  
  <pre><code>&lt;div class="img_transfer"&gt;
      &lt;img class="toggle" src="{{src}}"&gt;
      &lt;input class="title" type="text" name="title[{{i}}]" placeholder="Title"&gt;&lt;br&gt;
      Upload to Sta.sh:
      &lt;input type="radio" name="stash[{{i}}]" value="0" checked="checked"&gt; No
      &lt;input type="radio" name="stash[{{i}}]" value="1"&gt; Yes&lt;br&gt;
      Showcase:
      &lt;input type="radio" name="showcase[{{i}}]" value="0" checked="checked"&gt; No
      &lt;input type="radio" name="showcase[{{i}}]" value="1"&gt; Yes&lt;br&gt;
      &lt;input class="save" type="hidden" name="save[{{i}}]" value="0"&gt;
      &lt;input type="hidden" name="old_path[{{i}}]" value="{{old_path}}"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The <code>{{i}}</code> was a placeholder for a loop iteration, and this was working fine, but here's how I've been trying to do it in Symfony:</p>
  
  <pre><code>$img_tmp = glob('img_tmp/*.*');
  $data = array();
  foreach ($img_tmp as $src) {
      //$inter = end();
      $parts = explode('/', $src);
      $file = end($parts);
      //$name = explode($inter)[0];
      $name = explode('.', $file)[0];
      $data[$name] = new Art();
  }
  
  $builder = $this-&gt;createFormBuilder($data);
  foreach ($data as $key =&gt; $value) {
      //$builder-&gt;add($key, (new ArtType())-&gt;setSrc($key));
      $builder-&gt;add($key, ArtType::class, array('img_src' =&gt; $key));
  }
  
  $form = $builder-&gt;getForm();
  
  return $this-&gt;render('img_transfer.html.twig', array('form' =&gt; $form-&gt;createView()));
  </code></pre>
  
  <p>This is mostly based on another suggestion on SO for how to have a form of objects, but as is it will not let me send the custom option to the form to be built, which I think might be my final barrier to getting this to do what I had easily implemented by hand. I'm wholly welcome to suggestions and would prefer a less hack-y way of doing this, and also would love to know whether I'm just overlooking a simple way of doing this or if this is as horribly un-intuitive as I perceive it to be. I'll edit and restructure this to be a better question when I have time.</p>
  
  <p><strong>Edit:</strong> Formatting and the following additional information:
  This particular part of the application is supposed to take images of arbitrary name and extension dumped in the "web/img_tmp" directory, and move them into the "web/img" directory while renaming them with PHP's uniqid() and entering them into a database; I want something that generates a grouped set of fields for every "/img_tmp/<em>.</em>" that allows me to set attributes for each one before persisting them in the DB. All resources I've yet found on how to submit multiple objects at once have been either incomplete or woefully over-complicated.</p>