E
E
Express7772016-02-22 08:32:10
JavaScript
Express777, 2016-02-22 08:32:10

How to globally change error messages in YII2?

Hello.
Models in Yii2 have a custom message field for Javascript client-side validation:

public function rules()
    {
        return array(
            array('title, content', 'required',
                  'message'=>'Введите значение {attribute}.'),
                  // другие правила валидации
        );
    }

But this has to be written in each model.
But how to globally change JS validation messages so as not to write the same thing in each model?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Express777, 2016-02-22
@Express777

I found the answer on this site
pro-cod.ru/yii2-ustanovit-russkij-yazyk.html
I'll duplicate it just in case.
If you need to install the Russian language, just add the 'language' => 'ru-RU' parameter for the advanced template, this is the main.php file
path - root/common/config/main.php

<?php
return [
    'language' => 'ru-RU',
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
    ],
];

For the basic template, this is the web.php
path file - root/common/config/web.php

N
Nikita, 2016-02-22
@bitver

Write your own validators, so as not to bathe, you can copy / inherit the standard ones.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question