Answer the question
In order to leave comments, you need to log in
How to reconnect the error page depending on the error status?
My problem is that I can't reconnect the error page. I have a 404 page and 500. What did I do and what happened. According to the documentation, I looked at the frontend2/config/main.php configs. It stands there
'errorHandler' => [
'errorAction' => 'site/error',
],
namespace frontend2\controllers;
use yii\web\Controller;
class SiteController extends FrontendController
...
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
/**
* @brief Страница ошибки
* @return string
*/
public function actionError()
{
$exception = Yii::$app->errorHandler->exception;
if ($exception !== null) {
if ($exception->statusCode == 404) {
return $this->render('404', ['exception' => $exception]);
} else if ($exception->statusCode == 404) {
return $this->render('500', ['exception' => $exception]);
} else {
return $this->render('error', ['exception' => $exception]);
}
}
}
}
var_dump('Hello');die()
Answer the question
In order to leave comments, you need to log in
Good afternoon.
In the configuration, specify the path to your view for error output. In the view itself, check what the error status is and display the content accordingly.
// в конфигурационном файле
'errorHandler' => [
'errorAction' => 'path/to/error/view',
],
// в Вашем файле вывода ошибок
if($exception->statusCode == 404){
$this->title => 'Текст заголовка';
// остальные переменные
}
if($exception->statusCode == 500){
$this->title => 'Текст заголовка';
// остальные переменные
}
// остальной код файла
Well, yii\web\ErrorAction is also indicated to him.
Make your own frontend\components\ErrorAction and specify it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question