尝试创建用户时处理验证异常(Kohana 3.1 ORM / Auth 模块)
将 Kohana 3.1 与 Auth ORM 模块结合使用,如果我使用 create_user
创建一个新用户,如何处理验证异常并为页面中的每个用户显示错误?在这种情况下,密码太短(<8 个字符),但也可能是 password_confirm
与 password
不匹配。
$user = ORM::factory('user')
->where('username', '=', 'admin')->find();
if( ! $user->loaded())
{
$this->template->content = __('Admin user does not exist. Creating...');
$user = ORM::factory('user');
$user->create_user(
array(
'username' => 'admin',
'email' => '[email protected]',
'password' => 'admin',
'password_confirm' => 'admin'
),
array(
'username',
'email',
'password'
));
// remember to add the login role AND the admin role
// add a role; add() executes the query immediately
$user->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
$user->add('roles', ORM::factory('role')->where('name', '=', 'admin')->find());
}
Using Kohana 3.1 with the Auth ORM module, if I create a new user using create_user
, how can I handle validation exceptions and display an error for each one in the page? In this case, the password is to short (< 8 characters), but it could also be that password_confirm
does not match password
.
$user = ORM::factory('user')
->where('username', '=', 'admin')->find();
if( ! $user->loaded())
{
$this->template->content = __('Admin user does not exist. Creating...');
$user = ORM::factory('user');
$user->create_user(
array(
'username' => 'admin',
'email' => '[email protected]',
'password' => 'admin',
'password_confirm' => 'admin'
),
array(
'username',
'email',
'password'
));
// remember to add the login role AND the admin role
// add a role; add() executes the query immediately
$user->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
$user->add('roles', ORM::factory('role')->where('name', '=', 'admin')->find());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望您已经找到了问题的答案,但无论如何:
Hope you've already found an answer to your question but anyway: