saving in two tables using one form

hi guys please help i’m a codeigniter developer and trying to learn yii.

my problem is i want to save data to two tables were one data is the employee and the other is EmployeeChildren

the EmployeeChildren should be an array since one employee can have many children.so the idea is to have a text box for employee fields and a list for EmployeeChildren field an add button where i can add children to list and save button to save all the data to there respective table.

Design:

Tables:

  1. Employee

-employeeId

-name

  1. EmployeeChildren

-employeeId

-childName

-birthDate

the form design should be like this

text[employeeId] List[Children]

text[name] button[add] button[remove]

button[Save]

yes you can pass the array in controller ,

in controller make two object of different model and you can save different array elements in different table using model of that table .

Take a look at this wiki.

thanks for the reply guys.

now how do i save the children where children are in array.

employe:

001

scrypt

i.t

children:

1

boy

2

girl

any sample code for this?.

I got it! thanks for hint guys…

Hello scrypt new to Yii here. Can i ask how did you do it?

saving one-to-many in one form.

regards,

rvinnix

Have a look at this wiki as well.

http://www.yiiframework.com/wiki/323/dynamic-parent-and-child-cgridciew-on-single-view-using-ajax-to-update-child-gridview-via-controller-with-many_many-relation-after-row-in-parent-gridview-was-clicked/#hh7

See the "Another use case" section. It displays a parent record at the top and child records below that in a CGridView and dropdownlist. It saves the parent record and selected child records from the dropdownlist simultaneously.

thanks gerhard… i will look into that article.

http://www.yiiframework.com/forum/index.php/topic/52109-save-data-with-two-models/

please see the above link and help me to save the data to db…i’m also have the same problem but i don’t know how to do that…there i post my code so plz help me …