Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding constants and a property to track the current type.

This helps with resolving parent elements.
  • Loading branch information...
commit d8c6594ff6b34e682d1104c59a37f3035b503a5d 1 parent 9b2fd8f
@markstory markstory authored
Showing with 21 additions and 10 deletions.
  1. +21 −10 lib/Cake/View/View.php
View
31 lib/Cake/View/View.php
@@ -248,7 +248,7 @@ class View extends Object {
protected $_parents = array();
/**
- * The currently rendering view file.
+ * The currently rendering view file. Used for resolving parent files.
*
* @var string
*/
@@ -258,9 +258,9 @@ class View extends Object {
* Currently rendering an element. Used for finding parent fragments
* for elements.
*
- * @var boolean
+ * @var string
*/
- protected $_inElement = false;
+ protected $_currentType = '';
/**
* Content stack, used for nested templates that all use View::extend();
@@ -269,6 +269,10 @@ class View extends Object {
*/
protected $_stack = array();
+ const TYPE_VIEW = 'view';
+ const TYPE_ELEMENT = 'element';
+ const TYPE_LAYOUT = 'layout';
+
/**
* Constructor
*
@@ -353,9 +357,8 @@ public function element($name, $data = array(), $options = array()) {
$this->Helpers->trigger('beforeRender', array($file));
}
- $this->_inElement = true;
+ $this->_currentType = self::TYPE_ELEMENT;
$element = $this->_render($file, array_merge($this->viewVars, $data));
- $this->_inElement = false;
if ($callbacks) {
$this->Helpers->trigger('afterRender', array($file, $element));
@@ -400,6 +403,7 @@ public function render($view = null, $layout = null) {
$this->output = null;
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
+ $this->_currentType = self::TYPE_VIEW;
$this->Helpers->trigger('beforeRender', array($viewFileName));
$this->output = $this->_render($viewFileName);
$this->Helpers->trigger('afterRender', array($viewFileName));
@@ -462,7 +466,7 @@ public function renderLayout($content_for_layout, $layout = null) {
if (!isset($this->viewVars['title_for_layout'])) {
$this->viewVars['title_for_layout'] = Inflector::humanize($this->viewPath);
}
-
+ $this->_currentType = self::TYPE_LAYOUT;
$this->output = $this->_render($layoutFileName);
if ($this->output === false) {
@@ -618,10 +622,17 @@ public function end() {
* @return void
*/
public function extend($name) {
- if ($this->_inElement) {
- $parent = $this->_getElementFileName($name);
- } else {
- $parent = $this->_getViewFileName($name);
+ switch ($this->_currentType) {
+ case self::TYPE_VIEW:
+ $parent = $this->_getViewFileName($name);
+ break;
+ case self::TYPE_ELEMENT:
+ $parent = $this->_getElementFileName($name);
+ break;
+ case self::TYPE_LAYOUT:
+ $parent = $this->_getLayoutFileName($name);
+ break;
+
}
$this->_parents[$this->_current] = $parent;
}
Please sign in to comment.
Something went wrong with that request. Please try again.