gpt4 book ai didi

php - CakePhp - 相关数据不保存(但主模型数据确实保存)

转载 作者:行者123 更新时间:2023-12-04 05:17:35 25 4
gpt4 key购买 nike

所以,我在 CakePhp 中有一个使用 Formhelper 的表单。此表单中有两个关联模型:Booking 和 Guest。数据库表似乎设置正确,因为页面通过模型中的关联足够准确地填充值。

保存我的表单数据时,会保存预订信息,但不会保存客人信息。我已经简化了下面片段中的代码。任何想法我做错了什么?

型号

class Booking extends AppModel {
public $name = "Booking";

/*Associations Section*/
public $belongsTo = array('Property','Bookingsource');
public $hasMany = array('Payment','Occupant','Bookingfee');
public $hasAndBelongsToMany = array(
'Addon',
'Guest' => array(
'unique' => FALSE
)
);
}

Controller
public function edit($id) {
if ($this -> request -> is('post')) {
if ($this -> Booking -> saveAll($this -> request -> data)) {
$this -> Session -> setFlash('Booking Edited Successully!', "goodflash");
} else {
$this -> Session -> setFlash('Oops Something went wrong!', "badflash");
}
} else {
$this->data = $this -> Booking -> findById($id);
$this -> set('bookingid', $id);
}
}

查看
<?php
echo $this->Form->create("Booking", array('type' => 'post'));
echo $this -> Form -> hidden('Booking.id');
echo $this -> Form -> input('Booking.property_id');
echo $this -> Form -> input('Booking.checkin');
echo $this -> Form -> input('Booking.checkout');
echo $this -> Form -> input('Guest.0.firstname');
echo $this -> Form -> end("Submit");
?>

在查看正在处理的 SQL 时,我没有看到任何建议尝试编辑附加到我的模型的 Guest 表的内容。
5   UPDATE `cake_bookingsystem`.`bookings` SET `id` = '10000', `property_id` = '01', `checkin` = '2012-11-10', `checkout` = '2012-12-13' WHERE `cake_bookingsystem`.`bookings`.`id` = '10000'       0   0   8
6 COMMIT 0 0 8

最佳答案

尝试在您的 View 中添加访客记录的 id 字段:

<?php
echo $this->Form->create("Booking", array('type' => 'post'));
echo $this -> Form -> hidden('Booking.id');
echo $this -> Form -> input('Booking.property_id');
echo $this -> Form -> input('Booking.checkin');
echo $this -> Form -> input('Booking.checkout');
echo $this -> Form -> input('Guest.0.id');
echo $this -> Form -> input('Guest.0.firstname');
echo $this -> Form -> end("Submit");

?>

关于php - CakePhp - 相关数据不保存(但主模型数据确实保存),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14064522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com