我有一个控制器“前面”,我只想让这个控制器使用自定义错误操作。 我怎样才能做到这一点?我试过了this,但似乎无法正常工作
答案 0 :(得分:1)
我发现这个解决方案可以捕获异常
if ($model == null) {
// (I want the front layout only for this exception,so this 'throw' seems not to working as I want,it has the 'site' layout of site/error default error action )throw new NotFoundHttpException('The patient does not exist.');
$exception = new \yii\web\NotFoundHttpException("The patient does not exist");
$statusCode = $exception->statusCode;
$name = $exception->getName();
$message = $exception->getMessage();
return $this->render('error', [
'exception' => $exception,
'statusCode' => $statusCode,
'name' => $name,
'message' => $message
]);