Пользовательские сообщения об ошибках валидации в Kohana 3.0 - PullRequest
3 голосов
/ 29 сентября 2011

Я пытаюсь загрузить пользовательские сообщения об ошибках, чтобы использовать их при проверке формы регистрации.

Модель пользователя:

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

Таким образом, отправка пустой формы даетследующие сообщения об ошибках:

  • Имя пользователя не должно быть пустым
  • Адрес электронной почты не должен быть пустым
  • Пароль не должен быть пустым

Какие по умолчанию.

1 Ответ

5 голосов
/ 29 сентября 2011

Из класса Кохана 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')

...