如何在 Kohana 3.2 验证对象上调用修剪函数?

问题描述 投票:0回答:2

如何在 Kohana 3.2 中的验证对象上调用 trim 函数?我正在使用:

$post = Validation::factory($this->request->post());
$post->rule('Email', 'trim');
php kohana
2个回答
4
投票

从 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

2
投票

除了 Darsstar 回复 - 如果您需要

array_map
的递归版本,请查看 Arr::map 函数:

$post = Arr::map('trim', $this->request->post());
© www.soinside.com 2019 - 2024. All rights reserved.