mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
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
This commit is contained in:
parent
157bdfafc6
commit
8f31ef7149
2 changed files with 12 additions and 7 deletions
|
@ -379,7 +379,7 @@ class View extends Object {
|
|||
}
|
||||
|
||||
if ($action !== false && $viewFileName = $this->_getViewFileName($action)) {
|
||||
$out = $this->_render($viewFileName, $this->viewVars);
|
||||
$out = $this->_render($viewFileName);
|
||||
}
|
||||
|
||||
if ($layout === null) {
|
||||
|
@ -425,13 +425,13 @@ class View extends Object {
|
|||
}
|
||||
$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();
|
||||
|
@ -439,10 +439,9 @@ class View extends Object {
|
|||
$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 @@ class View extends Object {
|
|||
* @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 @@ class ViewTest extends CakeTestCase {
|
|||
$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');
|
||||
|
|
Loading…
Reference in a new issue