Yii Framework Forum: saving in two tables using one form - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

saving in two tables using one form saving data in two tables using one form Rate Topic: -----

#1 User is offline   scrypt 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 29-June 11

Posted 29 June 2011 - 11:29 PM

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

2. EmployeeChildren
-employeeId
-childName
-birthDate

the form design should be like this
text[employeeId] List[Children]
text[name] button[add] button[remove]

button[Save]
0

#2 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 493
  • Joined: 21-May 11
  • Location:India

Posted 30 June 2011 - 01:01 AM

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 .
Thanks,
Kiran Sharma.
0

#3 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 30 June 2011 - 01:09 AM

Take a look at this wiki.
0

#4 User is offline   scrypt 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 29-June 11

Posted 03 July 2011 - 11:12 PM

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?.
0

#5 User is offline   scrypt 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 29-June 11

Posted 15 July 2011 - 02:18 AM

I got it! thanks for hint guys..
0

#6 User is offline   rvinnix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 01-June 11

Posted 11 July 2012 - 10:08 AM

View Postscrypt, on 15 July 2011 - 02:18 AM, said:

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
0

#7 User is offline   Gerhard Liebenberg 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 343
  • Joined: 07-January 12
  • Location:Stillbay - Western Cape - South Africa

Posted 11 July 2012 - 03:17 PM

Have a look at this wiki as well.

http://www.yiiframew...as-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.
0

#8 User is offline   rvinnix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 01-June 11

Posted 11 July 2012 - 08:08 PM

View PostGerhard Liebenberg, on 11 July 2012 - 03:17 PM, said:

Have a look at this wiki as well.

http://www.yiiframew...as-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.
0

#9 User is offline   MohammedNizamudeen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 23-November 13

Posted 05 March 2014 - 09:07 AM

http://www.yiiframew...ith-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 ..
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users