Я плохо знаком с 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));
}
}
?>
Да, можно.
$this->Model->begin(); // Start transaction
$this->Model->commit(); // Commit transaction
$this->Model->rollback(); // Rollback transaction