Skip to content

Instantly share code, notes, and snippets.

@yidas
Last active August 1, 2018 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yidas/0bcf11a3d43f7f909bc750f63af089c6 to your computer and use it in GitHub Desktop.
Save yidas/0bcf11a3d43f7f909bc750f63af089c6 to your computer and use it in GitHub Desktop.
[Yii2] Yii2 sample code of Error Action handling such 404 errors

[Yii2] Yii2 sample code of Error Action handling such 404 errors

/**
 * Error action
 *
 * @return void
 */
public function actionError()
{
    $exception = Yii::$app->errorHandler->exception;
    // Error route
    switch ($exception->statusCode) {
        case 404:
            $this->layout = 'empty';
            return $this->render('error_404', ['exception' => $exception]);
            break;

        default:
            $this->redirect('/');
            break;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment