From 9f71bf400e4879716d8d5baf33bf1d5dfa67b340 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 30 Jul 2016 15:07:56 +0300 Subject: [PATCH] Fixes #12038: Introduced `yii\base\ViewNotFoundException` which is thrown when views file doesn't exists, used it in `ViewAction` --- framework/CHANGELOG.md | 1 + framework/base/View.php | 7 ++++--- framework/base/ViewNotFoundException.php | 25 +++++++++++++++++++++++++ framework/web/ViewAction.php | 3 ++- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 framework/base/ViewNotFoundException.php diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index ecb3087..a48d932 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -15,6 +15,7 @@ Yii Framework 2 Change Log - Bug #12045: Added missing `LEVEL_PROFILE` to `yii\log\Logger::getLevelName()` map (Mak-Di) - Enh #10583: Do not silence session errors in debug mode (samdark) - Enh #12048: Improved message extraction command performance (samdark) +- Enh #12038: Introduced `yii\base\ViewNotFoundException` which is thrown when views file doesn't exists, used it in `ViewAction` (samdark) 2.0.9 July 11, 2016 ------------------- diff --git a/framework/base/View.php b/framework/base/View.php index 53c0eab..c8ca30d 100644 --- a/framework/base/View.php +++ b/framework/base/View.php @@ -140,7 +140,8 @@ class View extends Component * in the view. If the context implements [[ViewContextInterface]], it may also be used to locate * the view file corresponding to a relative view name. * @return string the rendering result - * @throws InvalidParamException if the view cannot be resolved or the view file does not exist. + * @throws ViewNotFoundException if the view file does not exist. + * @throws InvalidCallException if the view cannot be resolved. * @see renderFile() */ public function render($view, $params = [], $context = null) @@ -211,7 +212,7 @@ class View extends Component * @param object $context the context that the view should use for rendering the view. If null, * existing [[context]] will be used. * @return string the rendering result - * @throws InvalidParamException if the view file does not exist + * @throws ViewNotFoundException if the view file does not exist */ public function renderFile($viewFile, $params = [], $context = null) { @@ -223,7 +224,7 @@ class View extends Component if (is_file($viewFile)) { $viewFile = FileHelper::localize($viewFile); } else { - throw new InvalidParamException("The view file does not exist: $viewFile"); + throw new ViewNotFoundException("The view file does not exist: $viewFile"); } $oldContext = $this->context; diff --git a/framework/base/ViewNotFoundException.php b/framework/base/ViewNotFoundException.php new file mode 100644 index 0000000..191b05e --- /dev/null +++ b/framework/base/ViewNotFoundException.php @@ -0,0 +1,25 @@ +controller->layout = $controllerLayout; } - } catch (InvalidParamException $e) { + } catch (ViewNotFoundException $e) { if ($controllerLayout) { $this->controller->layout = $controllerLayout;