Can Kohana 3 validation errors be inherited?

I created a bunch of errors in the file under APPPATH/messages/validate.phpwith a bunch of generic messages like ...

return array(
    'not_empty'    => ':field must not be empty.',
    'matches'      => ':field must be the same as :param1',
    'regex'        => ':field does not match the required format',
    'exact_length' => ':field must be exactly :param1 characters long',
    'min_length'   => ':field must be at least :param1 characters long',
    'max_length'   => ':field must be less than :param1 characters long',
    'in_array'     => ':field must be one of the available options',
    'digit'        => ':field must be a digit',
    'email'        => 'You must enter a valid email.',
    'name'         => 'You must enter your name.',
    'enquiry'      => 'You must enter your enquiry.',
    'captcha' => array (
        'Captcha::valid' => 'The characters you entered did not match the image. Please try again.',
        'not_empty' => 'You must enter the characters from the image.'
    ) 
);

This works great when I get errors like $errors = $post->errors('validate').

Is there a way to use these errors as basic errors, and if I have a separate form that needs more, I can use a separate file with only differences in it, for example, it may look like

return array(
    'permissions'    => 'Please agree to the permissions',
);

Obviously, any error message emailwill be received from validate.php(inherited), but any error permissionswill be received from the new file with the error definition for permissions.

validate.php, , , system, , SYSPATH/messages/validate.php (. GitHub).

?

+3
4

, :

  • +
  • +
  • validate

, validate , .

+2

: APPPATH/messages/validate.php

return array(
    'email'        => 'You must enter a valid email.',
    'name'         => 'You must enter your name.',
    'enquiry'      => 'You must enter your enquiry.',
    'captcha' => array (
        'Captcha::valid' => 'The characters you entered did not match the image. Please try again.',
        'not_empty' => 'You must enter the characters from the image.'
    )
);

: APPPATH/messages/specific.php

return array(
    'permissions'    => 'Please agree to the permissions',
);

Kohana , : APPPATH/messages/specific.php, APPPATH/messages/validate.php SYSPATH/messages/validate.php

print_r(validate->errors('specific'));
+4

"":

    $orm->values($form[$this->name])->check();

    $not_model_errors = Validate::factory(array())->rule(NULL, 'permissions_rules'); // doesn't matter what args you send here, just meet the vartype
    // add test error
    $not_model_errors->error(NULL, 'test_error', array());

    $this->template->errors = $orm->validate()->errors('validation') + $not_model_errors->errors('permissions');

.

+3

, !

$commonErrors = include APPPATH .  'messages/validate.php';

$errors =  array(
    'permission' => array(
        'not_empty' => 'You must give permission to continue.'
    )
);

return array_merge($commonErrors, $errors);

, !

0

Source: https://habr.com/ru/post/1753441/


All Articles