Skip to content

Commit

Permalink
Removing magic 'title' key in Controller::set() and View::set()
Browse files Browse the repository at this point in the history
Removing Controller::$pageTitle and View::$pageTitle.
Instead you should set('title_for_layout', $val) from your view or controller.
Test cases updated.
  • Loading branch information
markstory committed Sep 29, 2009
1 parent 622e500 commit 070bbb5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 43 deletions.
10 changes: 1 addition & 9 deletions cake/libs/controller/controller.php
Expand Up @@ -33,7 +33,6 @@
* @package cake
* @subpackage cake.cake.libs.controller
* @link http://book.cakephp.org/view/49/Controllers
*
*/
class Controller extends Object {

Expand Down Expand Up @@ -713,14 +712,7 @@ function set($one, $two = null) {
} 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);
}

/**
Expand Down
41 changes: 11 additions & 30 deletions cake/libs/view/view.php
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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'
);

Expand Down Expand Up @@ -461,27 +453,25 @@ function renderLayout($content_for_layout, $layout = null) {
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);
Expand Down Expand Up @@ -630,9 +620,8 @@ function entity() {
*
* @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;
Expand All @@ -645,18 +634,10 @@ function set($one, $two = null) {
} 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);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion cake/tests/cases/libs/controller/controller.test.php
Expand Up @@ -749,7 +749,8 @@ function testControllerSet() {
$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');
Expand Down
3 changes: 0 additions & 3 deletions cake/tests/cases/libs/view/view.test.php
Expand Up @@ -833,9 +833,6 @@ function testSet() {
$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');
Expand Down

0 comments on commit 070bbb5

Please sign in to comment.