diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index ad7600b1f..fd1999e9a 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -381,8 +381,13 @@ class View extends Object { } if (is_file($file)) { - $params = array_merge_recursive($params, $this->loaded); - $element = $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers); + $vars = array_merge($this->viewVars, $params); + 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)) { cache('views' . DS . $cacheFile, $element, $expires); } diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index 4905cad20..8ffb0837a 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -487,6 +487,24 @@ class ViewTest extends CakeTestCase { $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 * diff --git a/cake/tests/test_app/views/elements/type_check.ctp b/cake/tests/test_app/views/elements/type_check.ctp new file mode 100644 index 000000000..a863c2b48 --- /dev/null +++ b/cake/tests/test_app/views/elements/type_check.ctp @@ -0,0 +1 @@ + \ No newline at end of file