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

发布于 2024-12-07 06:11:53 字数 1462 浏览 0 评论 0原文

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

用户模型:

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

帐户控制器:

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

注册视图:

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

因此,提交空表单会出现以下错误消息:

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

这是默认的。

I'm attempting to load custom error messages to use when validating my 'sign up' form.

User model:

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

Account Controller:

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

Sign Up View:

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

I then placed user.php in /messages/models/user.php but my new error messages are not being displayed in the form.

<?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

So submitting an empty form gives the following error messages:

  • Username must not be empty
  • Email Address must not be empty
  • Password must not be empty

Which are the default ones.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤凫 2024-12-14 06:11:53

来自 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')

From Kohana Validation class, errors method source code:

 * 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');  

Try using $errors = $post->errors('models/user') instead $errors = $post->errors('signup')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文