1
그래서 Formhelper를 사용하여 CakePhp에 양식이 있습니다. 이 양식에는 두 개의 연관된 모델이 있습니다. 예약 & 손님. 페이지가 모델의 연관성을 통해 정확하게 정확하게 값을 채우므로 데이터베이스 테이블이 올바르게 설정되어있는 것처럼 보입니다.CakePhp - 관련 데이터 저장 안 함 (기본 모델 데이터 저장 제외)
양식 데이터를 저장할 때 예약 정보는 저장되지만 게스트 정보는 저장하지 않습니다. 아래 스 니펫의 코드를 단순화했습니다. 내가 뭘 잘못하고 있는거야?
모델
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
)
);
}
컨트롤러
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 테이블을 편집하려는 시도를 제안하지는 않습니다. 또한보기에 게스트 레코드의 id 필드를 추가
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
?. 아직도 운이 없다. 다시 메인 예약 정보에 대한 변경 사항은 커밋되지만 게스트에 대한 변경 사항은 없습니다. 실망! –
나는 약간의 질문을 편집하여 추가하거나 추가하는 동안 게스트 테이블에 쓰여지는 모든 데이터가 SQL –
을 포함하도록 편집했습니다. –