Fixes #1297: CSRF not generated on error pages

This commit is contained in:
Qiang Xue
2013-11-24 17:41:09 -05:00
parent 72dd86df15
commit 4b353c7bce
5 changed files with 16 additions and 10 deletions

View File

@ -22,14 +22,14 @@ return [
],
```
After it is done in case of error Yii will launch `SiteController::actionError()`. Since errors are converted to
exceptions we can get exception from error handler:
After it is done in case of error, Yii will launch `SiteController::actionError()`:
```php
public function actionError()
{
$exception = \Yii::$app->getErrorHandler()->exception;
$this->render('myerror', ['message' => $exception->getMessage()]);
if (\Yii::$app->exception !== null) {
return $this->render('error', ['exception' => \Yii::$app->exception]);
}
}
```
@ -48,7 +48,7 @@ public function actions()
```
After defining `actions` in `SiteController` as shown above you can create `views/site/error.php`. In the view there
are three varialbes available:
are three variables available:
- `$name`: the error name
- `$message`: the error message