⚠ 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

Problem with callback_after_update and two tables update/insert



Aradiel

Aradiel
  • profile picture
  • Member

Posted 07 October 2014 - 17:50 PM

I have problem with callback_after_update function i can't find good exemple for resolving my  issue.
 
I have two tables "scaner_table" and "scaner_table_history".
First one is working great but i would like to add after update function  those same data to history table something as logfile. Note the fields on both tables are not 100% same. History table contains more fields.

 

I managed something like that:

public function scanero() {
	$this->db = $this->load->database('scaner',true);
	$crud = new grocery_CRUD();
	$crud->set_table('scaner_table');
	$crud->columns('type','number','serial_number','ip','status','location','change_date','text');
	$crud->unset_delete();
 	$crud->callback_after_insert(array($this, 'history_after_update'));
	$crud->callback_after_update(array($this, 'history_after_update'));
	$output = $crud->render();
	$this->_example_output($output);
    }

function history_after_update($post_array,$primary_key) {	
	$this->db = $this->load->database('skaner',true);
	$crud = new grocery_CRUD();

	$history_insert = array(
		"type" => $type,
		"number" => $number,
		"serial_number" => $serial_number,
		"ip" => $ip,
		"status" => $status,
		"location" => $location,
		"change_date"=> date('Y-m-d H:i:s'),
		"text" => $text,
		"last_update" => date('Y-m-d H:i:s')
	);

	$this->db->insert('scaner_table_history',$history_insert);
return true;
}    

There is no error message and nothing happends after pressing update button. Page is not even returning to the grid view.

 

I tried lots of combinations but i think i miss something in my coding logic or i need to take different approach to this but i can't figure out how can i do that

 


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 08 October 2014 - 05:20 AM

Hi there,

 

Welcome to the GC World.

 

Well the first things .. u dont need to re instantiate the GC in a callback function - its totally un necessary

Secondly.. the issue that i foresee is the insert object you trying to build.. where are the variable values you getting from??? they are not declared... that is probably 1 reason...

secondly... it might be causing issue entering the same into database.... that might be another issue...

Your configuration might not be error display friendly ... hence no errors are being popped up for the same.

 

well 1 more thing that you can do is .. create a trigger to achieve the same target - it will be better.

 

Hope this information can help you for the same.

 

Happy GCing :)