Skip to content

Commit

Permalink
Fix issue where including elements + extending views fails.
Browse files Browse the repository at this point in the history
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
markstory committed Oct 1, 2012
1 parent 739b3b7 commit affb319
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/Cake/Test/Case/View/ViewTest.php
Expand Up @@ -1397,6 +1397,22 @@ public function testExtendMissingElement() {
$this->View->render('extend_missing_element');
}

/**
* 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.
*
Expand Down
3 changes: 3 additions & 0 deletions lib/Cake/Test/test_app/View/Posts/extend_with_element.ctp
@@ -0,0 +1,3 @@
<?php echo $this->element('test_element'); ?>
<?php $this->extend('parent_view'); ?>
The view
6 changes: 6 additions & 0 deletions lib/Cake/View/View.php
Expand Up @@ -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)));
}
Expand Down

0 comments on commit affb319

Please sign in to comment.