2011-09-28 90 views
1

有没有使用Kohana(3+)验证类而不使用消息文件的方法?没有消息文件的Kohana验证

[编辑]

下面是一个例子:

$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'); 

错误消息将从消息文件被readed,但我想硬编码在源代码中的错误消息。例如:

$post->rules->('username', 'not_empty', 'Please give your username'); 
+2

你能澄清你的意思吗?“不使用消息文件”?你想从其他来源设置验证错误消息吗? – Dickie

+0

您将在代码中导致问题。 –

+0

@ ThePixelDeveloper如果我在代码中硬编码错误消息,或者您是否想要其他东西,会导致问题? –

回答

1

你不得不延长验证public function errors($file = NULL, $translate = TRUE)public function rules($field, array $rules)public function rule($field, $rule, array $params = NULL)方法和使用自己的代码实现。

+0

是的,似乎这是做到这一点的唯一方法。我想我会写我自己的轻量级验证类。 –