0

I am trying to make a custom error page in Yii2 advanced template. I was checking the following doc: Handling Errors

So I created actionError() in SiteController.

I was able to get the $exception with following:

$exception = Yii::$app->errorHandler->exception;

But i couldn't get the $name and $message.

From the $exception I got following:

yii\web\NotFoundHttpException Object
(
    [statusCode] => 404
    [message:protected] => Page not found.
    [string:Exception:private] => 
    [code:protected] => 0

    ... (more lines here) ...

    [trace:Exception:private] => Array
        (
        )

    [previous:Exception:private] => 
)

From here I see that I can get status code by $exception->statusCode, but can't access the message. How to fetch and pass both status code and message to view?

1 Answer 1

4

Property message is protected. Use getMessage() function to get the value:

$exceptionMessage = $exception->getMessage();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.