CodeIgniter Forums
Separate model methods to manage transactions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Separate model methods to manage transactions (/showthread.php?tid=28688)



Separate model methods to manage transactions - El Forum - 03-18-2010

[eluser]SerGz[/eluser]
Hi, all!
If i've got 2(or more) model methods which do (for example) enrolling/withdrawing, and one controller's method that calls 2 of these model methods.
Is it a good way(maybe, any suggestions how to do it better) to write 2model methods like these:
Code:
public function start_transaction(){
    $this->db->trans_start();
}

public function end_transaction(){
   $this->db->trans_complete();
}
And call in controller's method:
Code:
public function smth(){
   //something
   $this->model->start_transaction();
   $this->model->enroll();
   //something else
   $this->model->withdraw();
   $this->model->end_transaction();
}
Will transaction be reversed, if withdraw() method fails?
Thanks.