Permalink
Browse files

Fix issue where including elements + extending views fails.

If you include an element before calling extend(), the parent view
will be assumed to be an element instead of a view/layout.

Fixes #3248
  • Loading branch information...
1 parent 739b3b7 commit affb3192adb0084b55265f2a6758050ce9a300fd @markstory markstory committed Oct 1, 2012
@@ -1398,6 +1398,22 @@ public function testExtendMissingElement() {
}
/**
+ * Test extend() preceeded by an element()
+ *
+ * @return void
+ */
+ public function testExtendWithElementBeforeExtend() {
+ $this->View->layout = false;
+ $result = $this->View->render('extend_with_element');
+ $expected = <<<TEXT
+Parent View.
+this is the test elementThe view
+
+TEXT;
+ $this->assertEquals($expected, $result);
+ }
+
+/**
* Test that setting arbitrary properties still works.
*
* @return void
@@ -0,0 +1,3 @@
+<?php echo $this->element('test_element'); ?>
+<?php $this->extend('parent_view'); ?>
+The view
View
@@ -415,9 +415,15 @@ public function element($name, $data = array(), $options = array()) {
$this->getEventManager()->dispatch(new CakeEvent('View.beforeRender', $this, array($file)));
}
+ $current = $this->_current;
+ $restore = $this->_currentType;
+
$this->_currentType = self::TYPE_ELEMENT;
$element = $this->_render($file, array_merge($this->viewVars, $data));
+ $this->_currentType = $restore;
+ $this->_current = $current;
+
if ($callbacks) {
$this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($file, $element)));
}

0 comments on commit affb319

Please sign in to comment.