在Kohana 3.2中,在保存时通过Model_User
的外部验证,为什么不会显示正确的消息?
我在application/messages/models
中有user.php
,它读取和翻译"内部"数据很好,而_external.php
位于application/messages/models/user
中。
当_external data无效时,将显示来自Kohana的默认错误消息,因此没有正确翻译或给出来自Model_User
的正确标签。
// 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);
}
因此,当$extra
变量与规则不匹配时,我希望从application/messages/models/user/_external.php
获得不错的错误消息,看起来像:
return array(
'email' => array(
'email' => ':field must be a valid email address',
),
'name' => array(
'not_empty' => ':field must not be empty',
),
);
另外,如果:字段是从Model_User "labels"中获取的,那就太好了。
您需要将_external.php
放在messages/models
目录中的user.php
旁边,而不是messages/models/user
目录中。