title: active form multi model and multi attributes in Yii2
body: <p>In my project, I have an aggregation between, let's say, a University model and a Department model: a university have at least one department, while every department belongs to only one university.
  I'd like to have a possibility to create a university model instance with some number of department model instances and the exact number of departments is not known in advance (but at least one must exist). So, when creating a university, I'd like to have a page with one default department and an "Add Department" button that would allow me by means of javascript to add any number of departments that I need.</p>
  
  <p><strong>The question is:</strong> how should I write the create view page using ActiveForm in order that my POST array has the following structure:</p>
  
  <pre><code>   "University" =&gt; ["name" =&gt; "Sorbonne", "city" =&gt; "Paris"],
     "Faculty" =&gt; [
         0 =&gt; ["name" =&gt; "Medicine", "dean" =&gt; "Person A"], 
         1 =&gt; ["name" =&gt; "Physics", "dean" =&gt; "Person B"],
         2 =&gt; ["name" =&gt; "Mathematics", "dean" =&gt; "Person C"],
         ...
     ]
  </code></pre>
  
  <p>that I then pass to Faculty::loadMultiple() method.</p>
  
  <p>I've tried something like this</p>
  
  <pre><code>   $form = ActiveForm::begin();
     echo $form-&gt;field($university, 'name')-&gt;textInput();
     echo $form-&gt;field($university, 'city')-&gt;textInput();
     foreach ($faculties as $i =&gt; $faculty) {
         echo $form-&gt;field($faculty, "[$i]name")-&gt;textInput();
         echo $form-&gt;field($faculty, "[$i]dean")-&gt;textInput()
     }
     ActiveForm::end();
  </code></pre>
  
  <p>It works, but when adding new department by means of javascript (I just clone an html node that contains department input fields), I am forced to elaborate the numbers coming from variable $i of the above php script. And this is quite annoying.</p>
  
  <p>Another possibility that I've tried was to get rid of variable $i and write something like</p>
  
  <pre><code>    $form = ActiveForm::begin();
      echo $form-&gt;field($university, 'name')-&gt;textInput();
      echo $form-&gt;field($university, 'city')-&gt;textInput();
      foreach ($faculties as $faculty) {
          echo $form-&gt;field($faculty, "[]name")-&gt;textInput();
          echo $form-&gt;field($faculty, "[]dean")-&gt;textInput()
      }
      ActiveForm::end();
  </code></pre>
  
  <p>In this way, cloning the corresponding node is very simple, but the generated POST array has wrong structure due to [] brackets.</p>
  
  <p>Is it possible to modify the latter approach and to have the required structure of the POST array? </p>