• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Combining $userModel->save() with Transactions

#1
Hi,

I have a pretty complex form that requires multiple table rows to be either inserted, updated or a combination of the two.

I was wondering if it is at all possible to use the $userModel->save() in conjunction with tranaction as this would be a very convenient way of updating my table without the need for a complex rollback function, something like? 

PHP Code:
protected $table      'mytable';
protected 
$primaryKey 'id';

protected 
$returnType 'array';
    
protected 
$allowedFields = [
    'column1''column2''column3''column4''column5'
];    
    
public function 
addEditVals($vals) {
    $db db_connect();        
    $this->db->transStart();
    foreach($vals as $valArray) {
        $this->save($valArray);
    }
    $this->db->transComplete();
    if ($this->db->transStatus() === FALSE) {
        log_message('notice''[ERROR] {file}-{line}, Failed to Add/Edit Table - '.session('user_name'));
        return false;
    }else{
        log_message('notice''[SUCCESS] {file}-{line}, Table Added/Updated  - '.session('user_name'));
        return true;
    }


Thanks in advance Smile
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.