Jump to content


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

wahyuhandy

    Newbie

  • 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();
    $crud->set_table($table_name);

    if ($CI->session->userdata('privileges') > 2) {
        $crud->unset_add();
        $crud->unset_print();
        $crud->unset_export();
        $crud->unset_edit();
        $crud->unset_delete();
    } elseif ($CI->session->userdata('privileges') > 1) {
        $crud->unset_delete();
        $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);
}






Also tagged with one or more of these keywords: callback_after_insert, logs, grocerycrud, php, codeigniter

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users