Reputation: 357
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?
Upvotes: 0
Views: 4534
Reputation: 5032
Property message
is protected
. Use getMessage()
function to get the value:
$exceptionMessage = $exception->getMessage();
Upvotes: 4