Jump to content


xheradon

Member Since 01 Mar 2017
Offline Last Active Jul 02 2018 08:49 AM
-----

#15269 adding another parameter in a callback function

Posted xheradon on 22 June 2017 - 07:41 AM

Try $this->your_variable = "your variable" and then accessing inside your callback $this->your_variable;




#14947 Problem with callback in validation rule

Posted xheradon on 02 March 2017 - 08:41 AM

Solution:

 

If anyone is having the same problem, is because of the use of hmvc. To fix it: 

 

In application/libraries/grocery_crud.php:

 

1. add 

protected $hmvc;

2. change 

public function __construct(){}

for

public function __construct($hmvc = null) { $this->hmvc = $hmvc; }

3. replace

protected function form_validation()

	{

		if ($this->form_validation === null)

		{

			$this->form_validation = new grocery_CRUD_Form_validation();



		    if ($this->hmvc)

				$this->form_validation->CI = $this->hmvc;			

			

			$ci = &get_instance();

			$ci->load->library('form_validation');

			$ci->form_validation = $this->form_validation;

		}

		return $this->form_validation;

	}

Then, in your controller:

$crud = new grocery_CRUD($this);

instead of 

$crud = new grocery_CRUD();

No more needed. Then, if you use is_unique in $crud->set_rules you will get an error. To fix it just change isset to is_object in /libraries/Form_validation.php:

public function is_unique($str, $field)
	{
            //change isset to is_object()
		sscanf($field, '%[^.].%[^.]', $table, $field);
		return is_object($this->CI->db)
			? ($this->CI->db->limit(1)->get_where($table, array($field => $str))->num_rows() === 0)
			: FALSE;
	}