Removing magic 'title' key in Controller::set() and View::set()

Removing Controller::$pageTitle and View::$pageTitle.
Instead you should set('title_for_layout', $val) from your view or controller.
Test cases updated.
This commit is contained in:
mark_story 2009-09-28 21:23:40 -04:00
parent 622e500943
commit 070bbb5d0e
4 changed files with 14 additions and 43 deletions

View file

@ -33,7 +33,6 @@ App::import('View', 'View', false);
* @package cake
* @subpackage cake.cake.libs.controller
* @link http://book.cakephp.org/view/49/Controllers
*
*/
class Controller extends Object {
@ -713,14 +712,7 @@ class Controller extends Object {
} else {
$data = array($one => $two);
}
foreach ($data as $name => $value) {
if ($name === 'title') {
$this->pageTitle = $value;
} else {
$this->viewVars[$name] = $value;
}
}
$this->viewVars = array_merge($this->viewVars, $data);
}
/**

View file

@ -133,14 +133,6 @@ class View extends Object {
*/
var $layoutPath = null;
/**
* Title HTML element of this View.
*
* @var string
* @access public
*/
var $pageTitle = false;
/**
* Turns on or off Cake's conventional mode of rendering views. On by default.
*
@ -272,7 +264,7 @@ class View extends Object {
*/
var $__passedVars = array(
'viewVars', 'action', 'autoLayout', 'autoRender', 'ext', 'base', 'webroot',
'helpers', 'here', 'layout', 'name', 'pageTitle', 'layoutPath', 'viewPath',
'helpers', 'here', 'layout', 'name', 'layoutPath', 'viewPath',
'params', 'data', 'plugin', 'passedArgs', 'cacheAction'
);
@ -461,27 +453,25 @@ class View extends Object {
unset($this->viewVars['cakeDebug']);
}
if ($this->pageTitle !== false) {
$pageTitle = $this->pageTitle;
} else {
$pageTitle = Inflector::humanize($this->viewPath);
}
$data_for_layout = array_merge($this->viewVars, array(
'title_for_layout' => $pageTitle,
$dataForLayout = array_merge($this->viewVars, array(
'content_for_layout' => $content_for_layout,
'scripts_for_layout' => join("\n\t", $this->__scripts),
'cakeDebug' => $debug
));
if (!isset($dataForLayout['title_for_layout'])) {
$dataForLayout['title_for_layout'] = Inflector::humanize($this->viewPath);
}
if (empty($this->loaded) && !empty($this->helpers)) {
$loadHelpers = true;
} else {
$loadHelpers = false;
$data_for_layout = array_merge($data_for_layout, $this->loaded);
$dataForLayout = array_merge($dataForLayout, $this->loaded);
}
$this->_triggerHelpers('beforeLayout');
$this->output = $this->_render($layoutFileName, $data_for_layout, $loadHelpers, true);
$this->output = $this->_render($layoutFileName, $dataForLayout, $loadHelpers, true);
if ($this->output === false) {
$this->output = $this->_render($layoutFileName, $data_for_layout);
@ -630,9 +620,8 @@ class View extends Object {
*
* @param mixed $one A string or an array of data.
* @param mixed $two Value in case $one is a string (which then works as the key).
* Unused if $one is an associative array, otherwise serves as the
* values to $one's keys.
* @return unknown
* Unused if $one is an associative array, otherwise serves as the values to $one's keys.
* @return void
*/
function set($one, $two = null) {
$data = null;
@ -645,18 +634,10 @@ class View extends Object {
} else {
$data = array($one => $two);
}
if ($data == null) {
return false;
}
foreach ($data as $name => $value) {
if ($name == 'title') {
$this->pageTitle = $value;
} else {
$this->viewVars[$name] = $value;
}
}
$this->viewVars = array_merge($this->viewVars, $data);
}
/**

View file

@ -749,7 +749,8 @@ class ControllerTest extends CakeTestCase {
$this->assertTrue(array_key_exists('ModelName', $Controller->viewVars));
$Controller->set('title', 'someTitle');
$this->assertIdentical($Controller->pageTitle, 'someTitle');
$this->assertIdentical($Controller->viewVars['title'], 'someTitle');
$this->assertNotEqual($Controller->pageTitle, 'someTitle');
$Controller->viewVars = array();
$expected = array('ModelName' => 'name', 'ModelName2' => 'name2');

View file

@ -833,9 +833,6 @@ class ViewTest extends CakeTestCase {
$this->assertIdentical($View->viewVars, array('somekey' => 'someValue'));
$this->assertIdentical($View->getVars(), array('somekey'));
$View->set('title', 'my_title');
$this->assertIdentical($View->pageTitle, 'my_title');
$View->viewVars = array();
$keys = array('key1', 'key2');
$values = array('value1', 'value2');