How can I call the trim function on a validation object in Kohana 3.2? I am using:
$post = Validation::factory($this->request->post());
$post->rule('Email', 'trim');
Validation objects are read only as of 3.2. Filter the input before creating the Validation object like so:
$post = array_map('trim', $this->request->post()); // $post[key] = expression; if it is for one specific value
$post = Validation::factory($post);
// set validation rules etc
In addition to Darsstar reply - if you need recursive version of array_map
, check out Arr::map function:
$post = Arr::map('trim', $this->request->post());
来源:https://stackoverflow.com/questions/7906320/how-do-i-call-the-trim-function-on-a-kohana-3-2-validation-object