Browse Source

Fixes #12038: Introduced `yii\base\ViewNotFoundException` which is thrown when views file doesn't exists, used it in `ViewAction`

tags/2.0.10
Alexander Makarov 8 years ago
parent
commit
9f71bf400e
  1. 1
      framework/CHANGELOG.md
  2. 7
      framework/base/View.php
  3. 25
      framework/base/ViewNotFoundException.php
  4. 3
      framework/web/ViewAction.php

1
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
-------------------

7
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;

25
framework/base/ViewNotFoundException.php

@ -0,0 +1,25 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\base;
/**
* ViewNotFoundException represents an exception caused by view file not found.
*
* @author Alexander Makarov
* @since 2.0.10
*/
class ViewNotFoundException extends InvalidParamException
{
/**
* @return string the user-friendly name of this exception
*/
public function getName()
{
return 'View not Found';
}
}

3
framework/web/ViewAction.php

@ -10,6 +10,7 @@ namespace yii\web;
use Yii;
use yii\base\Action;
use yii\base\InvalidParamException;
use yii\base\ViewNotFoundException;
/**
* ViewAction represents an action that displays a view according to a user-specified parameter.
@ -81,7 +82,7 @@ class ViewAction extends Action
$this->controller->layout = $controllerLayout;
}
} catch (InvalidParamException $e) {
} catch (ViewNotFoundException $e) {
if ($controllerLayout) {
$this->controller->layout = $controllerLayout;

Loading…
Cancel
Save