mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fix extending in loops.
This commit is contained in:
parent
70981d05ca
commit
69b1c33f1f
4 changed files with 20 additions and 0 deletions
|
@ -1158,6 +1158,18 @@ TEXT;
|
||||||
$this->View->render('extend_self');
|
$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.
|
* Test extend() in an element and a view.
|
||||||
*
|
*
|
||||||
|
|
2
lib/Cake/Test/test_app/View/Posts/extend_loop.ctp
Normal file
2
lib/Cake/Test/test_app/View/Posts/extend_loop.ctp
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<?php $this->extend('extend_loop_inner'); ?>
|
||||||
|
Outer element.
|
2
lib/Cake/Test/test_app/View/Posts/extend_loop_inner.ctp
Normal file
2
lib/Cake/Test/test_app/View/Posts/extend_loop_inner.ctp
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<?php $this->extend('extend_loop'); ?>
|
||||||
|
Inner loop element.
|
|
@ -619,6 +619,7 @@ class View extends Object {
|
||||||
*
|
*
|
||||||
* @param string $name The view or element to 'extend' the current one with.
|
* @param string $name The view or element to 'extend' the current one with.
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws LogicException when you extend a view with itself or make extend loops.
|
||||||
*/
|
*/
|
||||||
public function extend($name) {
|
public function extend($name) {
|
||||||
switch ($this->_currentType) {
|
switch ($this->_currentType) {
|
||||||
|
@ -636,6 +637,9 @@ class View extends Object {
|
||||||
if ($parent == $this->_current) {
|
if ($parent == $this->_current) {
|
||||||
throw new LogicException(__d('cake_dev', 'You cannot have views extend themselves.'));
|
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;
|
$this->_parents[$this->_current] = $parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue