mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Changing View::element() to not overwrite viewVars with helpers that
have the same name. Test added. Fixes #1354
This commit is contained in:
parent
48f32a11e0
commit
a830632071
3 changed files with 26 additions and 2 deletions
|
@ -381,8 +381,13 @@ class View extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_file($file)) {
|
if (is_file($file)) {
|
||||||
$params = array_merge_recursive($params, $this->loaded);
|
$vars = array_merge($this->viewVars, $params);
|
||||||
$element = $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers);
|
foreach ($this->loaded as $name => $helper) {
|
||||||
|
if (!isset($vars[$name])) {
|
||||||
|
$vars[$name] =& $this->loaded[$name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$element = $this->_render($file, $vars, $loadHelpers);
|
||||||
if (isset($params['cache']) && isset($cacheFile) && isset($expires)) {
|
if (isset($params['cache']) && isset($cacheFile) && isset($expires)) {
|
||||||
cache('views' . DS . $cacheFile, $element, $expires);
|
cache('views' . DS . $cacheFile, $element, $expires);
|
||||||
}
|
}
|
||||||
|
|
|
@ -487,6 +487,24 @@ class ViewTest extends CakeTestCase {
|
||||||
$this->assertPattern('/non_existant_element/', $result);
|
$this->assertPattern('/non_existant_element/', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that additional element viewVars don't get overwritten with helpers.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testElementParamsDontOverwriteHelpers() {
|
||||||
|
$Controller = new ViewPostsController();
|
||||||
|
$Controller->helpers = array('Form');
|
||||||
|
|
||||||
|
$View = new View($Controller);
|
||||||
|
$result = $View->element('type_check', array('form' => 'string'), true);
|
||||||
|
$this->assertEqual('string', $result);
|
||||||
|
|
||||||
|
$View->set('form', 'string');
|
||||||
|
$result = $View->element('type_check', array(), true);
|
||||||
|
$this->assertEqual('string', $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testElementCacheHelperNoCache method
|
* testElementCacheHelperNoCache method
|
||||||
*
|
*
|
||||||
|
|
1
cake/tests/test_app/views/elements/type_check.ctp
Normal file
1
cake/tests/test_app/views/elements/type_check.ctp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<?php echo gettype($form); ?>
|
Loading…
Add table
Reference in a new issue