You can set a default error message for each validation rule in application/messages/validate.php:
<?php
return array(
'not_empty' => 'Field is empty',
'Custom_Class::custom_method' => 'Some error'
);
This will return message 'Field is empty' for following example:
$post_values = array('title'=>'');
$validation = Validate::factory($post_values)
->rules('title', array(
'not_empty'=>NULL) );
if($validation->check()){
// save validated values
$post = ORM::factory('post');
$post->values($validation);
$post->save();
}
else{
$errors = $validation->errors(true);
}
You could also change the behaviour of default Validate class, by extending it in application/classes/validate.php:
class Validate extends Kohana_Validate
{
public function errors($file = NULL, $translate = TRUE)
{
// default behavior
if($file){
return parent::errors($file, $translate);
}
// Custom behaviour
// Create a new message list
$messages = array();
foreach ($this->_errors as $field => $set)
{
// search somewhere for your message
list($error, $params) = $set;
$message = Kohana::message($file, "{$field}.{$error}");
}
$messages[$field] = $message;
}
return $messages;
}