Skip to content
Permalink
Browse files

Making $scripts_for_layout and $content_for_layout regular viewVars. …

…This will allow helpers to manipulate them in callbacks.

Made $___dataForView an optional parameter, it defaults to $this->viewVars if left undefined. Refs #624
  • Loading branch information...
markstory committed Nov 1, 2010
1 parent 157bdfa commit 8f31ef714940d6b9527d28084c2fa95c0873081a
Showing with 12 additions and 7 deletions.
  1. +9 −7 cake/libs/view/view.php
  2. +3 −0 cake/tests/cases/libs/view/view.test.php
@@ -379,7 +379,7 @@ public function render($action = null, $layout = null, $file = null) {
}
if ($action !== false && $viewFileName = $this->_getViewFileName($action)) {
$out = $this->_render($viewFileName, $this->viewVars);
$out = $this->_render($viewFileName);
}
if ($layout === null) {
@@ -425,24 +425,23 @@ public function renderLayout($content_for_layout, $layout = null) {
}
$this->Helpers->trigger('beforeLayout', array(&$this));
$dataForLayout = array_merge($this->viewVars, array(
$this->viewVars = array_merge($this->viewVars, array(
'content_for_layout' => $content_for_layout,
'scripts_for_layout' => implode("\n\t", $this->_scripts),
));
if (!isset($dataForLayout['title_for_layout'])) {
$dataForLayout['title_for_layout'] = Inflector::humanize($this->viewPath);
if (!isset($this->viewVars['title_for_layout'])) {
$this->viewVars['title_for_layout'] = Inflector::humanize($this->viewPath);
}
$attached = $this->Helpers->attached();
if (empty($attached) && !empty($this->helpers)) {
$loadHelpers = true;
} else {
$loadHelpers = false;
$dataForLayout = array_merge($dataForLayout);
}
$this->output = $this->_render($layoutFileName, $dataForLayout, $loadHelpers, true);
$this->output = $this->_render($layoutFileName, array(), $loadHelpers, true);
if ($this->output === false) {
$this->output = $this->_render($layoutFileName, $data_for_layout);
@@ -662,13 +661,16 @@ public function loadHelpers() {
* @param boolean $cached Whether or not to trigger the creation of a cache file.
* @return string Rendered output
*/
protected function _render($___viewFn, $___dataForView, $loadHelpers = true, $cached = false) {
protected function _render($___viewFn, $___dataForView = array(), $loadHelpers = true, $cached = false) {
$attached = $this->Helpers->attached();
if (count($attached) === 0 && $loadHelpers === true) {
$this->loadHelpers();
$this->Helpers->trigger('beforeRender', array(&$this));
unset($attached);
}
if (empty($___dataForView)) {
$___dataForView = $this->viewVars;
}
extract($___dataForView, EXTR_SKIP);
ob_start();
@@ -665,6 +665,9 @@ function testRender() {
$this->assertPattern("/<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><title>/", $result);
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
$this->assertPattern("/<div id=\"content\">posts index<\/div>/", $result);
$this->assertTrue(isset($View->viewVars['content_for_layout']), 'content_for_layout should be a view var');
$this->assertTrue(isset($View->viewVars['scripts_for_layout']), 'scripts_for_layout should be a view var');
$this->PostsController->set('url', 'flash');
$this->PostsController->set('message', 'yo what up');

0 comments on commit 8f31ef7

Please sign in to comment.
You can’t perform that action at this time.