[英]cakephp, how to save data in two tables?
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($this->data)
保存数据我使用
$this->Room->save($this->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
一个是
rooms
另一种是roomates
公共密钥我想使用的是id_rooms
和id_roomates
For Room
build an array like below. 对于
Room
构建如下数组。 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)
. 然后将数据保存到房间表:
$this->Room->save($this->data)
。
Next build an array for second table, say Roomtitle
, as below: 接下来为第二个表构建一个数组,例如
Roomtitle
,如下所示:
$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)
. 并保存:
$this->Roomtitle->save($this->data)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.