1

In codeigniter what is the correct method of passing variables to the callback function? I have used this,

$var1 = 'some conditions';
$this->form_validation->set_rules("callback__is_value_unique[value, $var1]");

public function _is_value_unique($value, $var1){
echo $var1;
die;
}

This gave me output like shown below:-

value, some conditions

rather than,

some conditions

2
  • 1
    You can only send one custom parameter to the callback, and the 2 parameters in the callback function are the $_POST value and the extra one you sent. Commented Feb 3, 2014 at 8:56
  • Check this post stackoverflow.com/questions/4822692/… Commented Feb 13, 2014 at 21:01

2 Answers 2

1

You must only set your value!

$var1 = 'some conditions';
$this->form_validation->set_rules("callback__is_value_unique[value, $var1]");

public function _is_value_unique($value, $var1){
echo $var1;
die;
}
Sign up to request clarification or add additional context in comments.

Comments

1

From the docs..

If you need to receive an extra parameter in your callback function, just add it normally after the function name between square brackets, as in: "callback_foo[bar]", then it will be passed as the second argument of your callback function.

Sounds like you could only pass one extra argument. Which should be a string. If you want to pass more arguments, you could store them somewhere else and just pass an argument, which stores the location of the additional param.

$index = count($this->arguments);
$this->arguments[$index] = array('value', 'some conditions'/*, ...*/);
$this->form_validation->set_rules("callback__is_value_unique[$index]");

public function _is_value_unique($value, $index){
    $args = $this->argumts[$index];
    echo $args[1];
    die;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.