⚠ 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

Callback function not working for me.



joe

joe
  • profile picture
  • Member

Posted 24 January 2015 - 16:50 PM

$this->load->library('Grocery_CRUD');	

try {
	$crud = new grocery_CRUD();
	$crud->set_theme('flexigrid');
	$crud->set_table('vp_contacts')
		->where('venue_id',$this->session->userdata('venue_id'))
		->set_subject('Contacts')
		->columns('contact_updated','contact_fname','contact_lname','contact_email')
		->display_as('contact_fname','First Name')
		->display_as('contact_lname','Last Name')
		->display_as('contact_email','Email');
	$crud->fields('contact_updated','contact_fname','contact_lname','contact_email');
	//$crud->change_field_type('contact_updated','invisible');
	
        $crud->callback_before_insert(array($this,'set_time'));
	$crud->callback_before_update(array($this,'set_time'));

	$crud->required_fields('contact_fname','contact_lname');
			
			
	function set_time($post_array){
	       $post_array['contact_updated'] = date('Y-m-d H:i:s');
		return $this->db->insert('vp_contacts',$post_array);
	}
			
	$crud->unset_jquery();
	$output = $crud->render();

        } catch(Exception $e) {
            show_error($e->getMessage().' --- '.$e->getTraceAsString());
    	}

I'm running to an issue where $crud->callback_before_update / insert is not setting datetime and updating the contact records. Interesting enough all other fields allowed to be edited are working fine just 'contact_updated' remains default through attempts to edit and or insert new. Any advise please?


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 26 January 2015 - 17:58 PM

well this wont work for you for a simple reason ... you are not returning the modified $post_array back to the user...

u changing it.. and just returning the control.. but the original value of the $post_array that the function had earlier - remains the same...

u should return $post_array --- and it will work 4 u.

 

Happy GCing :)


joe

joe
  • profile picture
  • Member

Posted 27 January 2015 - 15:23 PM

cheers Amit! Thank you for your help.