Kohana 3.1 国家/地区验证回调
我正在尝试在我的网站上设置注册功能,我需要验证用户输入的选择类型国家/地区:
public function rules()
{
return array(
......
'country' => array(
array('not_empty'),
array('digit'),
array(array($this, 'country_from_list'), array(':validation', ':field'))
),
......
);
}
这是我的回调:
public static function country_from_list($values)
{
// array id => value
$countries = ORM::factory('country')->getActive('array');
return Validation::factory($values)
->rule('country', 'in_array', array(':value', $countries));
}
但它不起作用。有什么想法吗?我正在尝试从 Kohana 3.0.9 移植它......
I'm trying to setup the registration function on my site and I need to validate user's input of country of select type:
public function rules()
{
return array(
......
'country' => array(
array('not_empty'),
array('digit'),
array(array($this, 'country_from_list'), array(':validation', ':field'))
),
......
);
}
and here is my callback:
public static function country_from_list($values)
{
// array id => value
$countries = ORM::factory('country')->getActive('array');
return Validation::factory($values)
->rule('country', 'in_array', array(':value', $countries));
}
but it doesn't work. Any ideas? I'm trying to port it from Kohana 3.0.9...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将 Validation 对象传递给回调方法,则如果它不符合您的条件,您可以对其执行自定义错误。 (在回调内部:$validation->error(...))
否则,您的回调应该接受字段的值,返回 bool 并如下所示:
方法:
If you're passing the Validation object to the callback method, you can do a custom error on it if it fails your condition. (inside of your callback: $validation->error(...))
Otherwise, your callback should accept the field's value, return bool and look like this :
And the method:
有一个问题(至少)。下面:
实际上是一个数组,其中:
:value
字符串,ORM::factory('country')->getActive('array' 的结果)
,但我不是 Kohana 3.1 验证方面的专家 - 我听说它自 3.0 以来已经发生了变化。
There is one issue (at least). The following:
is actually an array, where:
:value
string,ORM::factory('country')->getActive('array')
,But I am not an expert in Kohana 3.1's validation - I heard it has changed since 3.0.