how to use form to collect data which from different model

I have three tables like tbl_A tbl_B tbl_C. tbl_B and tbl_C are relationed with tbl_A through A_ID. I create model through tal_A in gii and confirgure the function relations(). I use the CActiveForm to generate the view to end-users.

In this view. not only does it include field in tbl_A, but it also it include tbl_B and tbl_C.

my question is how to handle the field which not in tbl_A. To field in tbl_A. I use below code to render it.

<?php echo $form->textField($model,‘column name in tbl_A’,array(‘maxlength’=>50));?>

but I don’t know how to render field in tbl_B and tbl_C. or I should use the CForm. if it is. How could I do.


How to use a single form to collect data for two or more models should solve your problem

thx your help. But I went through the cookbook. To below code, I think it was used two forms A and B. am I right ?

$_POST[‘A’], $_POST[‘B’])

That’s one form, with two different models – $_POST[‘MODEL_NAME’] not $_POST[‘FORM_NAME’] (unless you have a CFormModel, but that’s a different story).

Follow that guide you can apply it to your code

<?php echo $form->textField($A,‘column name in tbl_A’,array(‘maxlength’=>50));?>

<?php echo $form->textField($B,‘column name in tbl_B’,array(‘maxlength’=>50));?>

You just have to make sure that these models are passed to views in action

thx a lot

How to make a save button with that two model? usually it’s like that:

thx a lot