In Kohana 3.2, passing external validation on Model_User upon save, why won’t the correct message show?
I have user.php in application/messages/models which reads and translates fine for the “internal” data, while _external.php resides in application/messages/models/user.
When _external data is invalid, the default error message from Kohana is shown, and thus not correctly translated or given the correct labels from Model_User.
Edit, with code:
// We have $_POST, register a new user
$user = ORM::factory('user');
/*
* Here a bunch of variables are set
*/
$extra = Validation::factory($_POST)->
rule('email', 'email')-> // I run this check, because in my Model_User, email is filtered through Encrypt
rule('name', 'not_empty'); // Same goes for name
try {
$user->save($extra);
} catch (ORM_Validation_Exception $e) {
$this->template->errors = $e->errors('models', true);
}
So, when $extra variables don’t match the rule, I would like to get nice error messages from application/messages/models/user/_external.php, which looks like:
return array(
'email' => array(
'email' => ':field must be a valid email address',
),
'name' => array(
'not_empty' => ':field must not be empty',
),
);
Also, it would be nice if :field was fetched from Model_User “labels”.
You need to put
_external.phpnext to youruser.phpin themessages/modelsdirectory, not in themessages/models/userdirectory. I had the same problem, it worked for me.