A different multiple models question

I’ve read a few posts and wikis discussing saving data from a form to 2 models.

My situation is that I want to collect a list of records from one model and use them to populate a form that will be saved to another model.

In other words, there will not be a relation between the models. I need to present a list (derived from model A) with some options - radiobutton, notes field and save all to model B. I will not be updating or linking back to model A whatsoever.

I am thinking that I should use Tabular input and use a simple SQL query to generate the list of items. How do I bind that list to a model attribute of model B though?

I am not sure if I completely understand what you want to achieve, but If you want to update only model B, I don’t see what is problem here. The only thing is that you need to pass two models to form, one that will be saved(model B), and one that will be used to populate same data(drop-down options, radio buttons). And in post action, just save model B, as you would do same like when you use only one model in form.

Maybe this is usefull for you: multimodelform

Getting closer.

How do I take an array from an SQL query and assign it to a model attribute?

Lets say my array returns 3 $key=>$value pairs. I need to take each $value and populate it into the model to save it.

In my form I have this:


<?php foreach($criteria as $i=>$item): ?>

<tr>

<td><?php echo $item; ?></td>

<td><?php echo CHtml::activeRadioButtonList($data,"[$i]compliant", array(0=>'No', 1=>'Yes', 2=>'N/A'), array('separator'=>' | ', 'labelOptions'=>array('style'=>'display:inline'))); ?></td>

<td><?php echo $form->textField($data,"[$i]notes"); ?></td>

</tr>



What I need to do is map $item (which is my $value) to $data [$i]criteriaName.

I don’t want the user to be able to EDIT this value, but I want it to be saved.