mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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
This commit is contained in:
parent
739b3b70f7
commit
affb3192ad
3 changed files with 25 additions and 0 deletions
|
@ -1397,6 +1397,22 @@ TEXT;
|
|||
$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.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<?php echo $this->element('test_element'); ?>
|
||||
<?php $this->extend('parent_view'); ?>
|
||||
The view
|
|
@ -415,9 +415,15 @@ class View extends Object {
|
|||
$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)));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue