是否有办法使用Kohana的(3+)验证类而不使用消息文件?
[编辑]下面是一个例子:
$post = Validate::factory($_POST);
$post
->rule('username', 'not_empty')
->rule('username', 'regex', array('/^[a-z_.]++$/iD'))
->rule('password', 'not_empty')
->rule('password', 'min_length', array('6'))
->rule('confirm', 'matches', array('password'))
->rule('use_ssl', 'not_empty');
错误消息将从消息文件中读取,但我想在源代码中硬编码错误消息。例如:
$post->rules->('username', 'not_empty', 'Please give your username');
您必须扩展验证public function errors($file = NULL, $translate = TRUE)
public function rules($field, array $rules)
和public function rule($field, $rule, array $params = NULL)
方法并使用您自己的代码实现。