Cleaning up and finishing code formatting changes in View class.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7854 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-11-09 03:37:24 +00:00
parent 16eebce7f7
commit fde0d21053

View file

@ -240,9 +240,9 @@ class View extends Object {
* @access protected * @access protected
*/ */
var $__passedVars = array( var $__passedVars = array(
'viewVars', 'action', 'autoLayout', 'autoRender', 'ext', 'base', 'webroot', 'viewVars', 'action', 'autoLayout', 'autoRender', 'ext', 'base', 'webroot',
'helpers', 'here', 'layout', 'name', 'pageTitle', 'layoutPath', 'viewPath', 'helpers', 'here', 'layout', 'name', 'pageTitle', 'layoutPath', 'viewPath',
'params', 'data', 'plugin', 'passedArgs', 'cacheAction' 'params', 'data', 'plugin', 'passedArgs', 'cacheAction'
); );
/** /**
* Scripts (and/or other <head /> tags) for the layout * Scripts (and/or other <head /> tags) for the layout
@ -386,7 +386,12 @@ class View extends Object {
if ($out !== false) { if ($out !== false) {
if ($layout && $this->autoLayout) { if ($layout && $this->autoLayout) {
$out = $this->renderLayout($out, $layout); $out = $this->renderLayout($out, $layout);
if (isset($this->loaded['cache']) && (($this->cacheAction != false)) && (Configure::read('Cache.check') === true)) { $isCached = (
isset($this->loaded['cache']) &&
(($this->cacheAction != false)) && (Configure::read('Cache.check') === true)
);
if ($isCached) {
$replace = array('<cake:nocache>', '</cake:nocache>'); $replace = array('<cake:nocache>', '</cake:nocache>');
$out = str_replace($replace, '', $out); $out = str_replace($replace, '', $out);
} }
@ -394,7 +399,8 @@ class View extends Object {
$this->hasRendered = true; $this->hasRendered = true;
} else { } else {
$out = $this->_render($viewFileName, $this->viewVars); $out = $this->_render($viewFileName, $this->viewVars);
trigger_error(sprintf(__("Error in view %s, got: <blockquote>%s</blockquote>", true), $viewFileName, $out), E_USER_ERROR); $msg = __("Error in view %s, got: <blockquote>%s</blockquote>", true);
trigger_error(sprintf($msg, $viewFileName, $out), E_USER_ERROR);
} }
return $out; return $out;
} }
@ -414,7 +420,7 @@ class View extends Object {
$debug = ''; $debug = '';
if (isset($this->viewVars['cakeDebug']) && Configure::read() > 2) { if (isset($this->viewVars['cakeDebug']) && Configure::read() > 2) {
$params = array('controller' => $this->viewVars['cakeDebug']); $params = array('controller' => $this->viewVars['cakeDebug']);
$debug = View::element('dump', $params, false); $debug = View::element('dump', $params, false);
unset($this->viewVars['cakeDebug']); unset($this->viewVars['cakeDebug']);
} }
@ -424,14 +430,12 @@ class View extends Object {
} else { } else {
$pageTitle = Inflector::humanize($this->viewPath); $pageTitle = Inflector::humanize($this->viewPath);
} }
$data_for_layout = array_merge($this->viewVars, $data_for_layout = array_merge($this->viewVars, array(
array( 'title_for_layout' => $pageTitle,
'title_for_layout' => $pageTitle, 'content_for_layout' => $content_for_layout,
'content_for_layout' => $content_for_layout, 'scripts_for_layout' => join("\n\t", $this->__scripts),
'scripts_for_layout' => join("\n\t", $this->__scripts), 'cakeDebug' => $debug
'cakeDebug' => $debug ));
)
);
if (empty($this->loaded) && !empty($this->helpers)) { if (empty($this->loaded) && !empty($this->helpers)) {
$loadHelpers = true; $loadHelpers = true;
@ -460,14 +464,8 @@ class View extends Object {
if ($this->output === false) { if ($this->output === false) {
$this->output = $this->_render($layoutFileName, $data_for_layout); $this->output = $this->_render($layoutFileName, $data_for_layout);
$msg = __("Error in layout %s, got: <blockquote>%s</blockquote>", true);
trigger_error( trigger_error(sprintf($msg, $layoutFileName, $this->output), E_USER_ERROR);
sprintf(
__("Error in layout %s, got: <blockquote>%s</blockquote>", true),
$layoutFileName, $this->output
),
E_USER_ERROR
);
return false; return false;
} }
@ -508,8 +506,7 @@ class View extends Object {
if ($this->layout === 'xml') { if ($this->layout === 'xml') {
header('Content-type: text/xml'); header('Content-type: text/xml');
} }
$out = str_replace('<!--cachetime:'.$match['1'].'-->', '', $out); echo str_replace('<!--cachetime:' . $match['1'] . '-->', '', $out);
echo $out;
return true; return true;
} }
} }
@ -581,7 +578,7 @@ class View extends Object {
function entity() { function entity() {
$assoc = ($this->association) ? $this->association : $this->model; $assoc = ($this->association) ? $this->association : $this->model;
return array_values(Set::filter( return array_values(Set::filter(
array($assoc, $this->modelId, $this->field, $this->fieldSuffix) array($assoc, $this->modelId, $this->field, $this->fieldSuffix)
)); ));
} }
/** /**
@ -681,8 +678,12 @@ class View extends Object {
} }
} }
$out = ob_get_clean(); $out = ob_get_clean();
$caching = (
isset($this->loaded['cache']) &&
(($this->cacheAction != false)) && (Configure::read('Cache.check') === true)
);
if (isset($this->loaded['cache']) && (($this->cacheAction != false)) && (Configure::read('Cache.check') === true)) { if ($caching) {
if (is_a($this->loaded['cache'], 'CacheHelper')) { if (is_a($this->loaded['cache'], 'CacheHelper')) {
$cache =& $this->loaded['cache']; $cache =& $this->loaded['cache'];
$cache->base = $this->base; $cache->base = $this->base;
@ -750,7 +751,9 @@ class View extends Object {
} }
} }
$loaded[$helper] =& new $helperCn($options); $loaded[$helper] =& new $helperCn($options);
$vars = array('base', 'webroot', 'here', 'params', 'action', 'data', 'themeWeb', 'plugin'); $vars = array(
'base', 'webroot', 'here', 'params', 'action', 'data', 'themeWeb', 'plugin'
);
$c = count($vars); $c = count($vars);
for ($j = 0; $j < $c; $j++) { for ($j = 0; $j < $c; $j++) {
@ -869,21 +872,20 @@ class View extends Object {
if ($error === 'missingView') { if ($error === 'missingView') {
$this->cakeError('missingView', array( $this->cakeError('missingView', array(
'className' => $this->name, 'className' => $this->name,
'action' => $this->action, 'action' => $this->action,
'file' => $file, 'file' => $file,
'base' => $this->base 'base' => $this->base
)); ));
return false; return false;
} elseif ($error === 'missingLayout') { } elseif ($error === 'missingLayout') {
$this->cakeError('missingLayout', array( $this->cakeError('missingLayout', array(
'layout' => $this->layout, 'layout' => $this->layout,
'file' => $file, 'file' => $file,
'base' => $this->base 'base' => $this->base
)); ));
return false; return false;
} }
} }
/** /**
* Return all possible paths to find view files in order * Return all possible paths to find view files in order
@ -926,4 +928,5 @@ class View extends Object {
return $this->element($name, $params, $loadHelpers); return $this->element($name, $params, $loadHelpers);
} }
} }
?> ?>