⚠ 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 forum is read-only and soon will be archived. ⚠

Callback_after_insert spawning multiple row in table

callback_after_insert logs grocerycrud php codeigniter

  • Please log in to reply
No replies to this topic

#1 wahyuhandy



  • Members
  • Pip
  • 1 posts

Posted 11 July 2017 - 03:45 PM

I'm trying to log admin activity and generating the crud via helper, it's working great but there's one problem.

When it's logging the data after the user just *updating* one row, it spawning like 4-6 insert AND update log data to the log table.

Can anyone help me in this case?


Here is my code in the helper.

function render_event($table_name)
    $CI = & get_instance();  
    $crud = new grocery_CRUD();

    if ($CI->session->userdata('privileges') > 2) {
    } elseif ($CI->session->userdata('privileges') > 1) {
        $crud->callback_after_insert(log_execution('insert', $table_name));
        $crud->callback_after_update(log_execution('update', $table_name));
    } else {
        $crud->callback_after_insert(log_execution('insert', $table_name));
        $crud->callback_after_update(log_execution('update', $table_name));

    return $crud->render();

and the log_execution() in the same helper file

function log_execution($exec, $table_name)
    $CI = & get_instance();  
    $log_data = array(
        'uid' => $CI->session->userdata('uid'),
        'username' => $CI->session->userdata('username'),
        'execution' => $exec,
        'table_name' => $table_name,
        'date_execution' => date('Y-m-d H:i:s')

    $CI->db->insert('operations_logs', $log_data);

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users