Fix extending in loops.

This commit is contained in:
mark_story 2011-12-24 00:03:51 -05:00 committed by Mark Story
parent 70981d05ca
commit 69b1c33f1f
4 changed files with 20 additions and 0 deletions

View file

@ -1158,6 +1158,18 @@ TEXT;
$this->View->render('extend_self');
}
/**
* Make sure that extending in a loop causes an exception
*
* @expectedException LogicException
* @return void
*/
public function testExtendLoop() {
$this->View->layout = false;
$this->View->render('extend_loop');
}
/**
* Test extend() in an element and a view.
*

View file

@ -0,0 +1,2 @@
<?php $this->extend('extend_loop_inner'); ?>
Outer element.

View file

@ -0,0 +1,2 @@
<?php $this->extend('extend_loop'); ?>
Inner loop element.

View file

@ -619,6 +619,7 @@ class View extends Object {
*
* @param string $name The view or element to 'extend' the current one with.
* @return void
* @throws LogicException when you extend a view with itself or make extend loops.
*/
public function extend($name) {
switch ($this->_currentType) {
@ -636,6 +637,9 @@ class View extends Object {
if ($parent == $this->_current) {
throw new LogicException(__d('cake_dev', 'You cannot have views extend themselves.'));
}
if (isset($this->_parents[$parent]) && $this->_parents[$parent] == $this->_current) {
throw new LogicException(__d('cake_dev', 'You cannot have views extend in a loop.'));
}
$this->_parents[$this->_current] = $parent;
}