Kohana 3.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 Kohana
Validation
类,errors
方法源代码:尝试使用
$errors = $post->errors('models/user')
代替$errors = $post->errors('signup')
From Kohana
Validation
class,errors
method source code:Try using
$errors = $post->errors('models/user')
instead$errors = $post->errors('signup')