Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 070bbb5d0e0623580e90b193f35a6e0e544e70ac 1 parent 622e500
@markstory markstory authored
View
10 cake/libs/controller/controller.php
@@ -33,7 +33,6 @@
* @package cake
* @subpackage cake.cake.libs.controller
* @link http://book.cakephp.org/view/49/Controllers
- *
*/
class Controller extends Object {
@@ -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);
}
/**
View
41 cake/libs/view/view.php
@@ -134,14 +134,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.
*
* @var boolean
@@ -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 @@ 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);
@@ -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;
@@ -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);
}
/**
View
3  cake/tests/cases/libs/controller/controller.test.php
@@ -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');
View
3  cake/tests/cases/libs/view/view.test.php
@@ -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');
Please sign in to comment.
Something went wrong with that request. Please try again.