Answer the question
In order to leave comments, you need to log in
How to handle Kohana 3.3 validation errors during user registration?
There is Kohana 3.3 installed on Apache server under Xubuntu 14.10 . The
controller is also written. application/classes/Controller/User.php
There are small wrappers of the entire application for more convenient templating; therefore, controllers are not inherited according to the standard scheme, but this never bothered me.
class Controller_User extends Controller_System_Template
public function action_signup()
{
// если юзер авторизован
if($this->_auth->logged_in())
{
// отправляем его на главную
$this->redirect("/");
}
// если есть данные
if ($post = $this->request->post())
{
try {
$user = ORM::factory('User')->create_user($post, array('username','email','password'));
$user->add('roles',ORM::factory('Role',array('name'=>'login')));
mail($post['email'],
'Регистрация на сайте SiteName',
'Вы были зерегестрированы на сайте SiteName, ваш логин: '.$post['username'].' Ваш пароль: '.$post['password']);
$this->redirect("/");
}
catch (ORM_Validtion_Exception $e)
{
$errors = $e->errors('validation');
return FALSE;
}
}
$this->template->content = View::factory('partials/users/signup');
}
ORM_Validation_Exception [ 0 ]: Failed to validate array
1271 $array = $this->_validation;
1272
1273 if (($this->_valid = $array->check()) === FALSE OR $extra_errors)
1274 {
1275
1276 $exception = new ORM_Validation_Exception($this->errors_filename(), $array);
1277
1278 if ($extra_errors)
1279 {
1280 // Merge any possible errors from the external object
1281 $exception->add_object('_external', $extra_validation);
application/messages/validation/user.php
<?php defined('SYSPATH') OR die('No direct script access.');
return array(
'username' => array(
'not_empty' => 'Поле должно быть не пустым',
'max_length' => 'Превышена длина поля',
),
'password' => array(
'not_empty' => 'Пароль задать надо',
),
'email' => array(
'not_empty' => 'Пустое поле',
'email' => 'Ошибка почты',
),
);
Answer the question
In order to leave comments, you need to log in
The error was in the line
Banal typo
catch (ORM_Valid a tion_Exception $e)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question