Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changing View::element() to not overwrite viewVars with helpers that

have the same name.
Test added.
Fixes #1354
  • Loading branch information...
commit a8306320717feb75f870b0c68eeeb5e708dae64f 1 parent 48f32a1
@markstory markstory authored
View
9 cake/libs/view/view.php
@@ -381,8 +381,13 @@ function element($name, $params = array(), $loadHelpers = false) {
}
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);
}
View
18 cake/tests/cases/libs/view/view.test.php
@@ -488,6 +488,24 @@ function testElement() {
}
/**
+ * 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
*
* @access public
View
1  cake/tests/test_app/views/elements/type_check.ctp
@@ -0,0 +1 @@
+<?php echo gettype($form); ?>
Please sign in to comment.
Something went wrong with that request. Please try again.