Kohana 3.2 Validation_Exception 将不支持Errors()

发布于 2024-12-07 10:46:55 字数 2069 浏览 0 评论 0原文

我正在尝试将错误消息添加到我的验证对象中。

它说错误不是 Validation_Exception 的方法。我知道...问题是我认为 $e 变量将是模型中验证类的实例。我的问题是如何附加错误消息?

错误:

ErrorException [致命错误]:调用未定义的方法 Validation_Exception::errors()

控制器:

208             // redirect to the user account
209             $this->request->redirect('user/profile');
210          } catch (Validation_Exception $e) {
211             // Get errors for display in view
212             // Note how the first param is the path to the message file (e.g. /messages/register.php)
213             $errors = $e->errors('register/user');
214             // Move external errors to main array, for post helper compatibility
215             $errors = array_merge($errors, (isset($errors['_external']) ? $errors['_external'] : array()));
216             $view->set('errors', $errors);
217             // Pass on the old form values
218             $_POST['password'] = $_POST['password_confirm'] = '';

模型:

$validation = Validation::factory($fields)
                    ->rules('username', $this->_rules['username'])
                    ->rule('username', array($this, 'username_available'), array(':validation', ':field'))
                    ->rules('email', $this->_rules['email'])
                    ->rule('email', array($this, 'email_available'), array(':validation', ':field'))
                    ->rules('password', $this->_rules['password'])
                    ->rules('password_confirm', $this->_rules['password_confirm']);
                    //->labels($_labels);

            if (Kohana::config('useradmin')->activation_code) {
                    $validation->rule('activation_code', array($this, 'check_activation_code'), array(':validation', ':field'));
            }

            if(!$validation->check())
            {
                    throw new Validation_Exception($validation, __('Your registering information is not valid.'));
            }

我真的不明白为什么会出现此错误。

I am trying to add the error messages to my validation object.

It says that errors is not a method of Validation_Exception. That I know... The thing is that I though the $e variable would be the instance of the Validation Class in the model. My question is how can attach the error messages?

Error:

ErrorException [ Fatal Error ]: Call to undefined method Validation_Exception::errors()

Controller:

208             // redirect to the user account
209             $this->request->redirect('user/profile');
210          } catch (Validation_Exception $e) {
211             // Get errors for display in view
212             // Note how the first param is the path to the message file (e.g. /messages/register.php)
213             $errors = $e->errors('register/user');
214             // Move external errors to main array, for post helper compatibility
215             $errors = array_merge($errors, (isset($errors['_external']) ? $errors['_external'] : array()));
216             $view->set('errors', $errors);
217             // Pass on the old form values
218             $_POST['password'] = $_POST['password_confirm'] = '';

Model:

$validation = Validation::factory($fields)
                    ->rules('username', $this->_rules['username'])
                    ->rule('username', array($this, 'username_available'), array(':validation', ':field'))
                    ->rules('email', $this->_rules['email'])
                    ->rule('email', array($this, 'email_available'), array(':validation', ':field'))
                    ->rules('password', $this->_rules['password'])
                    ->rules('password_confirm', $this->_rules['password_confirm']);
                    //->labels($_labels);

            if (Kohana::config('useradmin')->activation_code) {
                    $validation->rule('activation_code', array($this, 'check_activation_code'), array(':validation', ':field'));
            }

            if(!$validation->check())
            {
                    throw new Validation_Exception($validation, __('Your registering information is not valid.'));
            }

I really don't see why this error is accuring.

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

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

发布评论

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

评论(1

带刺的爱情 2024-12-14 10:46:55

您基本上已经回答了自己的问题 - Validation_Exception 没有 errors 方法。您需要从 Validation 对象调用它。

You have basically answered your own question - Validation_Exception doesn't have errors method. You need to call it from Validation object instead.

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