2011-09-28 33 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

是的,似乎這是做到這一點的唯一方法。我想我會寫我自己的輕量級驗證類。 –