我可以在cakephp中将多个参数传递给自定义验证函数吗
我正在使用CakePHP2.8.0。我有一个自定义验证器函数,我想传递它3个参数。第一个显然是$check,但第二个和第三个只是一些需要验证的文本。第二个参数很好,但第三个参数始终是某个数组,而它应该只是一个字符串。以下是我的验证规则和函数:我可以在cakephp中将多个参数传递给自定义验证函数吗,cakephp,Cakephp,我正在使用CakePHP2.8.0。我有一个自定义验证器函数,我想传递它3个参数。第一个显然是$check,但第二个和第三个只是一些需要验证的文本。第二个参数很好,但第三个参数始终是某个数组,而它应该只是一个字符串。以下是我的验证规则和函数: public $validate = array('commit_positions_funding_explain' => array( 'check_empty_dependent' => array(
public $validate = array('commit_positions_funding_explain' => array(
'check_empty_dependent' => array(
'rule' => array('check_empty_dependent', 'commit_positions_auth', '0'),
'message' => 'Please select an option',
)
),);
public function check_empty_dependent($check, $parent, $another){
//$another should be 0 but instead its an array that looks like the
//the validate array
//do some stuff
return true;
}
关于第三个参数为什么不起作用的任何想法都非常感谢。看起来这个数组值是在我没有传递第三个参数时发生的。这些验证函数的参数不能是可选的。当我确保所有调用此函数的验证规则都传递了$other的某个值时,一切正常。似乎在我没有传递第三个参数时发生了此数组值。这些验证函数的参数不能是可选的。当我确保所有调用此函数的验证规则都为$other传递了一些值时,一切正常