Browse Source

Move responsibility for setting default view vars from RequestHandler to XML,JSON views. CS fixes.

sam-at-github 12 years ago
parent
commit
39e4ab032c
3 changed files with 29 additions and 15 deletions
  1. 15 12
      src/Controller/Component/RequestHandlerComponent.php
  2. 7 2
      src/View/JsonView.php
  3. 7 1
      src/View/XmlView.php

+ 15 - 12
src/Controller/Component/RequestHandlerComponent.php

@@ -108,7 +108,7 @@ class RequestHandlerComponent extends Component {
  */
 	protected $_viewClassMap = array(
 		'json' => 'Json',
-		'xml'  => 'Xml',
+		'xml' => 'Xml',
 		'ajax' => 'Ajax'
 	);
 
@@ -142,7 +142,7 @@ class RequestHandlerComponent extends Component {
 		if (isset($this->request->params['_ext'])) {
 			$this->ext = $this->request->params['_ext'];
 		}
-		if(empty($this->ext) && $this->request->is('ajax')) {
+		if (empty($this->ext) && $this->request->is('ajax')) {
 			$this->ext = 'ajax';
 		}
 		if (empty($this->ext) || in_array($this->ext, array('html', 'htm'))) {
@@ -518,17 +518,20 @@ class RequestHandlerComponent extends Component {
 
 		if ($viewClass) {
 			$controller->viewClass = $viewClass;
-		} elseif (empty($this->_renderType)) {
-			$controller->viewPath .= DS . $type;
 		} else {
-			$controller->viewPath = preg_replace(
-				"/([\/\\\\]{$this->_renderType})$/",
-				DS . $type,
-				$controller->viewPath
-			);
-		}
-		$this->_renderType = $type;
-		$controller->layoutPath = $type;
+			if (empty($this->_renderType)) {
+				$controller->viewPath .= DS . $type;
+			} else {
+				$controller->viewPath = preg_replace(
+					"/([\/\\\\]{$this->_renderType})$/",
+					DS . $type,
+					$controller->viewPath
+				);
+			}
+
+			$this->_renderType = $type;
+			$controller->layoutPath = $type;
+		}
 
 		if ($this->response->getMimeType($type)) {
 			$this->respondAs($type, $options);

+ 7 - 2
src/View/JsonView.php

@@ -56,8 +56,13 @@ use Cake\Network\Response;
 class JsonView extends View {
 
 /**
- * JSON views are always located in the 'json' sub directory for
- * controllers' views.
+ * JSON layouts are always located in the json sub directory of `Layouts/`
+ * 
+ */
+	public $layoutPath = 'json';
+
+/**
+ * JSON views are always located in the 'json' sub directory for controllers' views.
  *
  * @var string
  */

+ 7 - 1
src/View/XmlView.php

@@ -57,7 +57,13 @@ use Cake\Utility\Xml;
 class XmlView extends View {
 
 /**
- * The subdirectory. XML views are always in xml.
+ * XML layouts are always located in the xml sub directory of `Layouts/`
+ *
+ */
+	public $layoutPath = 'xml';
+
+/**
+ * XML views are always located in the 'xml' sub directory for controllers' views.
  *
  * @var string
  */