php - Codeigniter Transaction inside Control -


since have several functions executing in following control single transaction couldn't surround each function transaction in model. did following way. please let me know if there problem. works fine now, have no idea whether concurrency issues or there other way?

if(isset($_post['btnsave']))         {             $mcodes = $_post['tblmcode'];             $count = count($mcodes);             //echo $count;              $issue = new materialissue_model();              $this->db->trans_start(); //here starts transaction             $issue->setissuecode($this->input->post('txtissuecode'));              if($issue->checknoexistence()) {                  $issue->setdate($this->input->post('txtdate'));                 $issue->setcustomer($this->input->post('txtcustomer'));                 $issue->setfromlocation($this->input->post('txtlocation'));                 $issue->setresponsible($this->input->post('txtresponsible'));                 $issue->setcomments($this->input->post('txtcomments'));                 $issue->settotal($this->input->post('txttotal'));                 $issue->setuser($this->session->userdata('username'));                 $issue->setstatus($this->input->post('txtstatus'));                  ($i = 0; $i < $count; $i++) {                      $issue->setmaterialcode($_post['tblmcode'][$i]);                     $issue->setmaterialname($_post['tblmname'][$i]);                     $issue->setcost($_post['tblcost'][$i]);                     $issue->setqty($_post['tblqty'][$i]);                     $issue->setsubtotal($_post['tblsubtotal'][$i]);                     $issue->saveissuedetail();                      $stock = new materialstock_model();                     $stock->setitemcode($_post['tblmcode'][$i]);                     $stock->setitemlocation($this->input->post('txtlocation'));                     $stock->setqty($_post['tblqty'][$i]);                     $stock->setrefno($this->input->post('txtissuecode'));                     $stock->setlasttransaction('material-issue');                     $stock->updatematerialissuestock();                       $transaction = new transaction_model();                     $transaction->setdescription("material-issue");                     $transaction->setitemcode($_post['tblmcode'][$i]);                     $transaction->setrecqty("0");                     $transaction->settransqty("0");                     $transaction->setissueqty($_post['tblqty'][$i]);                     $transaction->setdate($this->input->post('txtdate'));                     $transaction->setuser($this->session->userdata('username'));                     $transaction->savematerialtransaction();                   }                  $result = $issue->saveissue();                 $this->db->trans_complete(); //here ends transaction                 if ($result) {                      $message = new message_model();                     $data['message'] = $message->recordadded;                     $data['type'] = "success";                     $data['returnpage'] = base_url() . "index.php/materialissue_control/show";                     $data["print"] =  base_url() . "index.php/notegenerator_control/showmaterialissuenote?code=".$issue->getissuecode();                     $this->load->view('messageprint_view', $data);                  }              }else{                  $message = new message_model();                 $data['message'] = $message->issuecodeexists;                 $data['type'] = "error";                 $data['returnpage'] = base_url() . "index.php/materialissue_control/show";                 $this->load->view('message_view', $data);               }          } 

i prefer using trigger handle many functions in 1 controller, make mycode clean , easy track. example: user writes article, action call 1 action in model write_article combine 1 transaction, function run query : 1.insert post 2.lock count post category 3.lock count user post 4.lock count post date example in code

public function write_article($post) {     $this->cms->db->trans_start(true);         $this->cms->db->set('content', $posts->get_content());         $this->cms->db->insert('t_posts');     $this->cms->db->trans_complete();     if($this->cms->db->trans_status() === true){         $this->cms->db->trans_commit();     }else{         $this->cms->db->trans_rollback();     } } 

this reference trigger www.sitepoint.com/how-to-create-mysql-triggers