Skip to content

Commit

Permalink
Move responsibility for setting default view vars from RequestHandler…
Browse files Browse the repository at this point in the history
… to XML,JSON views. CS fixes.
  • Loading branch information
sgpinkus committed Apr 16, 2014
1 parent b0e0671 commit 39e4ab0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
27 changes: 15 additions & 12 deletions src/Controller/Component/RequestHandlerComponent.php
Expand Up @@ -108,7 +108,7 @@ class RequestHandlerComponent extends Component {
*/
protected $_viewClassMap = array(
'json' => 'Json',
'xml' => 'Xml',
'xml' => 'Xml',
'ajax' => 'Ajax'
);

Expand Down Expand Up @@ -142,7 +142,7 @@ public function initialize(Event $event) {
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'))) {
Expand Down Expand Up @@ -518,17 +518,20 @@ public function renderAs(Controller $controller, $type, array $options = array()

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);
Expand Down
9 changes: 7 additions & 2 deletions src/View/JsonView.php
Expand Up @@ -56,8 +56,13 @@
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
*/
Expand Down
8 changes: 7 additions & 1 deletion src/View/XmlView.php
Expand Up @@ -57,7 +57,13 @@
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
*/
Expand Down

0 comments on commit 39e4ab0

Please sign in to comment.