Question

I have created the following method in order to do the validation on the submitted data.

public function validate_create($array) {

    $array = Validation::factory($array)
        -> rules('username', $this - > _rules['username']);

    return $array;
}

The rules is defined as

protected $_rules = array(
    'username' = > array(
        'not_empty' = > NULL,
        'min_length' = > array(6),
        'max_length' = > array(32),
    )
);

The code is throwing the following exception when trying to execute the check() method.

ErrorException [ Warning ]: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given

Can any one advice how to solve this issue?

In signup.php the input field for username is defined as

< ?php echo Form::label('user_name','Username')? > < ?php echo Form::input('username'); ? >

Was it helpful?

Solution

The format for building the Validation object directly is different from that of your $_rules array.

You can see the correct method signature and definition documented here, and it'd probably be a good idea to also read the signature for Validation::rule.

In short, the rules() method wants an list of arrays, where for each inner array the first element is the validation function and the second an array of parameters to pass to it.

e.g.

$rules = array(
    array('not_empty', NULL),
    array('min_length', array(':value', 6))
);

$v = Validation::factory($values)
    ->rules('fieldname', $rules);

Note that this is different than the $_rules array (map) format that you are attempting to use where the key is the validation function and the parameters are the values.

Aslo, is there any reason you're building your own validation function instead of using the ORM::rules() method of validation?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top