如何在 Kohana 3.2 中的验证对象上调用 trim 函数?我正在使用:
$post = Validation::factory($this->request->post());
$post->rule('Email', 'trim');
从 3.2 开始,验证对象是只读的。在创建 Validation 对象之前过滤输入,如下所示:
$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
除了 Darsstar 回复 - 如果您需要
array_map
的递归版本,请查看 Arr::map 函数:
$post = Arr::map('trim', $this->request->post());