N
N
Nikita Dergachov2019-04-26 13:37:46
Yii
Nikita Dergachov, 2019-04-26 13:37:46

How to change error title in yii?

For error 404, the name of the error is "Not Found"(#404)" , for other errors, the name is also in English. At the same time, the error message is in Russian. Is it possible to change this without changing a lot of code?
5cc2dfc724d0a875088334.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2019-04-26
@vanillathunder

Good afternoon.
In the error.php file, you can use the $exception variable and use it to change the title of the error page.
It looks like this:

if($exception->statusCode == 404){$this->title = 'Где-то ошибка';}
/* остальной код файла */

This will result in the following
instead of
5cc2eb824d16c264476002.png

M
Moses Fender, 2019-04-26
@mosesfender

When you throw an error, write whatever you want in it.

throw new \yii\web\NotFoundHttpException("Тут пишу что хочу", 404);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question