Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecating View::$output.

Replacing it with a magic __get/__set to the content block.
This helps deprecate $content_for_layout as well.
  • Loading branch information...
commit 44a8d7907ed77ad0c20dbefc96f5ef00bf656cd0 1 parent c49e261
@markstory markstory authored
Showing with 27 additions and 20 deletions.
  1. +27 −20 lib/Cake/View/View.php
View
47 lib/Cake/View/View.php
@@ -184,13 +184,6 @@ class View extends Object {
public $uuids = array();
/**
- * Holds View output.
- *
- * @var string
- */
- public $output = false;
-
-/**
* An instance of a CakeRequest object that contains information about the current request.
* This object contains all the information about a request and several methods for reading
* additional information about the request.
@@ -400,7 +393,7 @@ public function render($view = null, $layout = null) {
if (!$this->_helpersLoaded) {
$this->loadHelpers();
}
- $this->output = null;
+ $this->output = '';
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
$this->_currentType = self::TYPE_VIEW;
@@ -412,11 +405,8 @@ public function render($view = null, $layout = null) {
if ($layout === null) {
$layout = $this->layout;
}
- if ($this->output === false) {
- throw new CakeException(__d('cake_dev', "Error in view %s, got no content.", $viewFileName));
- }
if ($layout && $this->autoLayout) {
- $this->output = $this->renderLayout($this->output, $layout);
+ $this->output = $this->renderLayout('', $layout);
}
$this->hasRendered = true;
return $this->output;
@@ -440,39 +430,40 @@ public function render($view = null, $layout = null) {
* - `$content_for_layout` is deprecated and will be removed in CakePHP 3.0.
* Use the `content` block instead.
*
- * @param string $content_for_layout Content to render in a view, wrapped by the surrounding layout.
+ * @param string $content Content to render in a view, wrapped by the surrounding layout.
* @param string $layout Layout name
* @return mixed Rendered output, or false on error
* @throws CakeException if there is an error in the view.
*/
- public function renderLayout($content_for_layout, $layout = null) {
+ public function renderLayout($content, $layout = null) {
$layoutFileName = $this->_getLayoutFileName($layout);
if (empty($layoutFileName)) {
- return $this->output;
+ return $this->Blocks->get('content');
}
+
if (!$this->_helpersLoaded) {
$this->loadHelpers();
}
+ if (empty($content)) {
+ $content = $this->Blocks->get('content');
+ }
$this->Helpers->trigger('beforeLayout', array($layoutFileName));
$scripts = implode("\n\t", $this->_scripts);
$scripts .= $this->get('meta') . $this->get('css') . $this->get('script');
$this->viewVars = array_merge($this->viewVars, array(
- 'content_for_layout' => $content_for_layout,
+ 'content_for_layout' => $content,
'scripts_for_layout' => $scripts,
));
if (!isset($this->viewVars['title_for_layout'])) {
$this->viewVars['title_for_layout'] = Inflector::humanize($this->viewPath);
}
+
$this->_currentType = self::TYPE_LAYOUT;
$this->output = $this->_render($layoutFileName);
- if ($this->output === false) {
- throw new CakeException(__d('cake_dev', "Error in layout %s, got no content.", $layoutFileName));
- }
-
$this->Helpers->trigger('afterLayout', array($layoutFileName));
return $this->output;
}
@@ -723,11 +714,27 @@ public function __get($name) {
return isset($this->request->params['action']) ? $this->request->params['action'] : '';
case 'params':
return $this->request;
+ case 'output':
+ return $this->Blocks->get('content');
}
return null;
}
/**
+ * Magic accessor for deprecated attributes.
+ *
+ * @param string $name Name of the attribute to set.
+ * @param string $value Value of the attribute to set.
+ * @return mixed
+ */
+ public function __set($name, $value) {
+ switch ($name) {
+ case 'output':
+ return $this->Blocks->set('content', $value);
+ }
+ }
+
+/**
* Interact with the HelperCollection to load all the helpers.
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.