From 992f8edcb096a561a453a6c34beffde700bd12b7 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 21 Feb 2014 16:41:33 -0500 Subject: [PATCH] proper implementation of View::viewFile. --- framework/base/View.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/framework/base/View.php b/framework/base/View.php index 3c45f4f211..b9c61ad94a 100644 --- a/framework/base/View.php +++ b/framework/base/View.php @@ -92,13 +92,12 @@ class View extends Component * @internal */ public $dynamicPlaceholders = []; + /** - * @var string the path of the view file currently being rendered. If the view is not - * in the process of rendering a view, this property is null. - * This property is mainly provided for information purpose and is maintained by [[renderFile()]]. - * Do not modify it. + * @var array the view files currently being rendered. There may be multiple view files being + * rendered at a moment because one may render a view file within another. */ - public $viewFile; + private $_viewFiles = []; /** @@ -223,9 +222,9 @@ class View extends Component if ($context !== null) { $this->context = $context; } - $output = ''; - $this->viewFile = $viewFile; + $this->_viewFiles[] = $viewFile; + if ($this->beforeRender()) { Yii::trace("Rendering view file: $viewFile", __METHOD__); $ext = pathinfo($viewFile, PATHINFO_EXTENSION); @@ -241,13 +240,21 @@ class View extends Component } $this->afterRender($output); } - $this->viewFile = null; + array_pop($this->_viewFiles); $this->context = $oldContext; return $output; } + /** + * @return string|boolean the view file currently being rendered. False if no view file is being rendered. + */ + public function getViewFile() + { + return end($this->_viewFiles); + } + /** * This method is invoked right before [[renderFile()]] renders a view file. * The default implementation will trigger the [[EVENT_BEFORE_RENDER]] event.