Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've taken a completely different approach, valuable suggestions are always welcome :) Hope this will be helpful for some of you.</p> <p>Controller:</p> <pre><code>public function actionCreate($survey_id, $meter_id) { $bays = $this-&gt;getBayCount($meter_id); for ($i=1;$i&lt;=$bays;$i++) { $model=new SurveyRecord; $model-&gt;survey_id = (int)$survey_id; $model-&gt;meter_id = (int)$meter_id; ${'inspection_'.$i} = new SurveyInspection($i); if(isset($_POST['SurveyRecord'], $_POST["SurveyInspection"][$i])) { $model-&gt;attributes = $_POST['SurveyRecord']; ${'inspection_'.$i}-&gt;attributes = $_POST["SurveyInspection"][$i]; echo '&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;pre&gt;'; print_r(${'inspection_'.$i}-&gt;attributes); echo '&lt;/pre&gt;'; } } for ($i=1;$i&lt;=$bays;$i++) { ${'inspection_'.$i} = new SurveyInspection($i); $inspection['inspection_'.$i] = ${'inspection_'.$i}; } $this-&gt;render('create',array( 'inspection'=&gt;$inspection, 'model'=&gt;$model )); } </code></pre> <p>View:</p> <pre><code>... &lt;div class="control"&gt; &lt;?php echo $form-&gt;dropDownListRow($model,'status_id',$model-&gt;getStatusId(),array('prompt'=&gt;'Select Status ...')); ?&gt; &lt;?php $meter=Meter::model()-&gt;findByPk($model-&gt;meter_id); $bays = count($meter-&gt;bays); ?&gt; &lt;?php for ($i=1; $i&lt;=$bays; $i++): ?&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $form-&gt;textFieldRow($inspection["inspection_$i"], "[$i]bay_id", array('readonly'=&gt;true, 'value'=&gt;"$i", 'class'=&gt;'span1')); ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $form-&gt;dropDownListRow($inspection["inspection_$i"], "[$i]bay_usage_id", $inspection["inspection_$i"]-&gt;getUsageId(), array('prompt'=&gt;'Bay Status ...') ); ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php endfor; ?&gt; &lt;/div&gt; ... </code></pre> <p>Credit: <a href="http://yiiblog.info/blog/index.php/post/108/Rename+ACtiveRecord+" rel="nofollow">http://yiiblog.info/blog/index.php/post/108/Rename+ACtiveRecord+</a>$_POST+array's+Name+to+update+multimodels</p> <p>Note: There's still some work to be done on the view/controller (doesn't seem to be able to select on $_POST for my dropdowns on second model), will post once I have fixed it.</p> <p>Thanks for your help @PeterM and @Ninad for your input.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload