没有消息文件的Kohana验证

时间:2011-09-28 10:20:28

标签: php validation kohana

有没有办法在不使用消息文件的情况下使用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');

1 个答案:

答案 0 :(得分:1)

您必须扩展验证public function errors($file = NULL, $translate = TRUE) public function rules($field, array $rules)public function rule($field, $rule, array $params = NULL)方法并使用您自己的代码实施。

相关问题