⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Extend model to log Insert Update and Delete operation



marvel
  • profile picture
  • Member

Posted 04 February 2016 - 14:48 PM

Hi to everyone

 

Is it possibile to extend grocery crud model to implement the CRUD log in an external table?

 

Actually i do that using callback in my controller like this

 

        $crud->callback_after_insert(function ($post_array,$primary_key)
            { $this->userlog->write('ss_EmployeeStatistic',$primary_key,'I'); }
        );
        $crud->callback_after_update(function ($post_array,$primary_key)
            { $this->userlog->write('ss_EmployeeStatistic',$primary_key,'U'); }
        );
        $crud->callback_after_delete(function ($primary_key)
            { $this->userlog->write('ss_EmployeeStatistic',$primary_key,'D'); }
        );

 

calling my library UserLog

 

class Userlog
{    
    protected $CI;

    public function __construct()
    {
            // Assign the CodeIgniter super-object
            $this->CI =& get_instance();
    }

    function write($tab,$key,$type)
    {    
        $log = array(
            'UserID' => 1,
            'LogTable' => $tab,
            'LogPK' => $key,
            'LogType' => $type, // I insert, U update, D delete
            'LogDate' => date('Y-m-d H:i:s')
        );
    
        $this->CI->db->insert('UserLog',$log);
    
        return true;
    }
}   

 

as you see, my library doesn't get "table name" and "type of operation" coming from callbacks automatically, like $primary_key :(

Which are the names of the variable with the table name, typo of operation etc...

 

Thak you  very much