yii2 : layout of error not work -
i have site rbac roles , when error not access pages white page error.
use these codes had layout didn't work true:
my sitecontrolle:
public function actionerror() { $exception = yii::$app->errorhandler->exception; if ($exception !== null) { $this->layout = 'main'; return $this->render('error', ['exception' => $exception]); } } i have function in sitecontroller , think problem this:
public function actions() { return [ 'error' => [ 'class' => 'yii\web\erroraction', ], 'captcha' => [ 'class' => 'yii\captcha\captchaaction', 'fixedverifycode' => yii_env_test ? 'testme' : null, ], ]; } main.php:
'errorhandler' => [ 'erroraction' => 'site/error', ], error. php view page
<?php use yii\helpers\html; $this->title = $name; ?> <div class="site-error"> <h1><?= html::encode($this->title) ?></h1> <div class="alert alert-danger"> <?= nl2br(html::encode($message)) ?> </div> <p> above error occurred while web server processing request. </p> <p> please contact if think server error. thank you. </p> i test web other error , understand other errors show in view layout truely access error not in layout
in setup yours method actionerror() in site controller never called, because declared error in method actions(), comment following lines:
'error' => [ 'class' => 'yii\web\erroraction', ], in site controller , should see error, looking @ view must pass values name , message properties, this:
public function actionerror() { $exception = yii::$app->errorhandler->exception; if ($exception !== null) { $this->layout = 'main'; return $this->render('error', ['name' => $exception->getcode(), 'message' => $exception->getmessage()]); } } of course site/error must available in browser (setup rules in controller , paths on file system needed).
Comments
Post a Comment