validation - Kohana 3.0 中的自定义验证错误消息

标签 validation kohana kohana-3

我正在尝试加载自定义错误消息以在验证我的“注册”表单时使用。

用户模型:

https://github.com/ashleyconnor/Egotist/blob/master/classes/model/user.php

账户管理员:

https://github.com/ashleyconnor/Egotist/blob/master/classes/controller/user/account.php

注册 View :

https://github.com/ashleyconnor/Egotist/blob/master/views/account/signup.php

然后我将 user.php 放在 /messages/models/user.php 中,但是我的新错误消息没有显示在表单中。

<?php defined('SYSPATH') or die('No direct script access.');

  return array
  (
     'username' => array
     (
        'not_empty' => 'your message',
        'max_length' => 'your message',
        'alpha_dash' => 'your message',
        'default' => 'default message'
     ),
  );

?>

https://github.com/ashleyconnor/Egotist/blob/master/messages/models/user.php

因此提交一个空表单会给出以下错误信息:

  • 用户名不能为空
  • 电子邮件地址不能为空
  • 密码不能为空

哪些是默认的。

最佳答案

来自Kohana Validation类,errors方法源码:

 * Returns the error messages. If no file is specified, the error message
 * will be the name of the rule that failed. When a file is specified, the
 * message will be loaded from "field/rule", or if no rule-specific message
 * exists, "field/default" will be used. If neither is set, the returned
 * message will be "file/field/rule".
 *
 * By default all messages are translated using the default language.
 * A string can be used as the second parameter to specified the language
 * that the message was written in.
 *
 *     // Get errors from messages/forms/login.php
 *     $errors = $Validation->errors('forms/login');  

尝试使用 $errors = $post->errors('models/user') 代替 $errors = $post->errors('signup')

关于validation - Kohana 3.0 中的自定义验证错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7590861/

相关文章:

sql - 如何在 Kohana 3 中配置 SQLite?

php - 保护 Cookie 和 session

php - 使用 Kohana 3,我如何从数据库类中获取最后一个插入 ID?

php - Laravel 支持 return Redirect::back()->withFile() 吗?

validation - Primeng 和 Angular 2 Controller 验证

php - 学习小花

php - Kohana 2.3.4 + LINUX - ErrorException [ fatal error ] : Class not found

javascript - 人们如何在 2013 年验证他们的网站?

javascript - 如何让 jQuery 验证以验证浏览器预填充的字段

kohana - 删除相关记录,有has_many关系