From 011fd5153945e401ab3d4cea1b45a61948b94958 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 6 Nov 2011 22:13:35 -0500 Subject: [PATCH] starting to refactor views. Adding comments. Incomplete. --- lib/Cake/View/JsonView.php | 37 ++++++++++++++++++++++++------------- lib/Cake/View/XmlView.php | 26 +++++++++++++++++++------- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/lib/Cake/View/JsonView.php b/lib/Cake/View/JsonView.php index 2661b0046..aae0ac976 100644 --- a/lib/Cake/View/JsonView.php +++ b/lib/Cake/View/JsonView.php @@ -1,9 +1,5 @@ set(array('posts' => $posts, 'serialize' => 'posts'));` + * + * When the view is rendered, the `$posts` view variable will be serialized + * into JSON. + * + * If you don't use the `serialize` key, you will need a view + layout just like a + * normal view. * * @package Cake.View + * @since CakePHP(tm) v 2.1.0 */ class JsonView extends View { @@ -53,13 +63,14 @@ class JsonView extends View { * @return string The rendered view. */ public function render($view = null, $layout = null) { - if ($view !== false && $viewFileName = $this->_getViewFileName($view)) { - $this->_render($viewFileName); + if (isset($this->viewVars['serialize'])) { + $serialize = $this->viewVars['serialize']; + $data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null; + return $this->output = json_encode($data); + } + if ($view !== false && $viewFileName = $this->_getViewFileName($view)) { + return $this->output = $this->_render($viewFileName); } - - $data = isset($this->viewVars['serialize']) ? $this->viewVars['serialize'] : null; - - return $this->output = json_encode($data); } } diff --git a/lib/Cake/View/XmlView.php b/lib/Cake/View/XmlView.php index a948180b3..d80c9e040 100644 --- a/lib/Cake/View/XmlView.php +++ b/lib/Cake/View/XmlView.php @@ -1,9 +1,5 @@ set(array('posts' => $posts, 'serialize' => 'posts'));` + * + * When the view is rendered, the `$posts` view variable will be serialized + * into XML. + * + * **Note** The view variable you specify must be compatible with Xml::fromArray(). + * + * If you don't use the `serialize` key, you will need a view + layout just like a + * normal view. * * @package Cake.View + * @since CakePHP(tm) v 2.1.0 */ class XmlView extends View {