Post Of Tabular Data

Hi,

As an example, lets say I have 2 models: Class, Students where each class can have multiple students. Lets say I want to have a single view where I load 4 classes at the same time, and i want to be able to add/edit/delete students to each class.

What I have working: I have the view with the 4 sections which uses partial renders to load the sub-views

What I cannot get to work: How in the POST (in the class controller) do I differentiate between the students for each class. At the moment the POST looks like this:




Student[0][StudentName]=class 1 student 1

Student[0][StudentAddress]=

Student[0][StudentName]=class 2 student 1

Student[0][StudentAddress]=

Student[0][StudentName]=class 3 student 1

Student[0][StudentAddress]=

Student[0][StudentName]=class 4 student 1

Student[0][StudentAddress]=



when I try to check $_POST[ClassModel][students] it says students is not defined…

The above it not real models, but i really hope you understand what I am asking :-/

Take a look at this extension and this wiki.

Fixed by assigning a unique name to each element. See name in the array below. $item is a model instance. $index is the count in the loop





<?php 

  echo $form->dropDownList($item,

                          "[$i]SpeciesID",       

                          HelperFunctions::getSpeciesList(), 

                          array('class'=>'span2', 

                                'name' =>'catch'.$index."[$i][SpeciesID]")); 

?>