How do I call the trim function on a Kohana 3.2 validation object?

安稳与你 提交于 2019-12-07 13:51:38

问题


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');

回答1:


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



回答2:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!