Welcome Guest, Not a member yet? Register   Sign In
Separate model methods to manage transactions
#1

[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.




Theme © iAndrew 2016 - Forum software by © MyBB