⚠ 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 before insert not working



Mamdouh AlRamadan
  • profile picture
  • Member

Posted 17 October 2013 - 05:22 AM

This is my code:

public function special_management()
	{
		try{
			$crud = new grocery_CRUD();

			$crud->set_theme('datatables');
			$crud->set_table('specialx');
			$crud->set_subject('Special');
			$crud->required_fields('something');
                        $crud->set_relation('variant_id', 'variant', 'item_number');
                        $crud->callback_before_insert(array($this,'check_special_validity'));
			$output = $crud->render();
			$this->_admin_output($output);

		}catch(Exception $e){
			show_error($e->getMessage().' --- '.$e->getTraceAsString());
		}
	}
        
        function check_special_validity($arr)
        {
            $this->load->model('specialx');
            $value = $this->specialx->check_special_on_item($arr['item_number'],$arr['expiration_date']);
            return $value;
        }

what's driving me crazy is that when I test on separate controller I get  

value = false
but GC ignores it and inserts into the database.
any help?

 

Update:

item_number is a result of set_relation so that's why it's not defined in $arr. 
my updated question would be how to pass it with $arr in callback.

Update 2:

Solved by passing the relational element instead of item_number.