开发者

cakephp, how to save data in two tables?

开发者 https://www.devze.com 2023-04-11 07:53 出处:网络
i have a simple form with two input fields and i would like to save the data from one field inside one table and the other one inside the second table.

i have a simple form with two input fields and i would like to save the data from one field inside one table and the other one inside the second table.

to save the data i use $this->Room->save($thi开发者_高级运维s->data)

any ideas how this can be done?

thanks

edit:

one is rooms the other one is roomates the common key i want to use is is id_rooms and id_roomates


For Room build an array like below. It is just an example, set it according to your actual fields.

$this->data['Room']['id_rooms'] = $this->data['Room']['id']
$this->data['Room']['abc'] = $this->data['Room']['xyz']

Then save data to room table: $this->Room->save($this->data).

Next build an array for second table, say Roomtitle, as below:

$this->data['Roomtitle']['id_rooms'] = $this->data['Room']['id']
$this->data['Roomtitle']['abc'] = $this->data['Room']['xyz']

and save it: $this->Roomtitle->save($this->data).

0

精彩评论

暂无评论...
验证码 换一张
取 消