저는 cakephp를 처음 사용합니다. cakephp에서 단일 트랜잭션으로 다중 모델 커밋 및 롤백을 처리 할 수 있는지 알고 싶습니다. 이런 일을하고 싶습니다.단일 트랜잭션 커밋 및 롤백을 사용하여 여러 모델로 트랜잭션 관리
<?php
function add(){
$transaction = begintransaction;
if(model1->save()){
if(model2->save()){
if(model3->save(){
}
else{
$errorFlag['model3'] = "Error in model 3";
}
}
else{
$errorFlag['model2'] = "Error in model 2";
}
}
else{
$errorFlag['model3'] = "Error in model 3";
}
if(empty($errorFlag)){ //no error in saving the model
$transaction->commit();
$this->Session->setFlash(__('The form data with multiple model is saved', true));
}
else{ //error in saving the model
$transaction->rollback();
$this->Session->setFlash(__('The form data with multiple model is saved', true));
}
}
?>
이 코드는 작동하지 않습니다. 정의되지 않은 속성 : MyController :: $ Model 모델이란 컨트롤러 용으로 정의 된 모델 클래스의 일부입니까? 그렇다면 그러한 거래에 다른 견해가 포함되어 있습니까? –
"모델"을 모델 클래스 이름으로 변경하십시오. 조회수에 대한 귀하의 질문을 이해하지 못했습니다. 특정 문제가있는 경우 새 질문을 엽니 다. – bancer