Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing regression cased by commit d5ffdc2 causing ajax layout to be n…

…ot auto set for ajax request for html pages. Refs #1099
  • Loading branch information...
commit b9a7b27ba1f8434a5f16d755a08ecc55a0e597cf 1 parent b648b61
ADmad ADmad authored
14 cake/libs/controller/components/request_handler.php
View
@@ -230,15 +230,17 @@ function startup(&$controller) {
$this->__initializeTypes();
$controller->params['isAjax'] = $this->isAjax();
+ $isRecognized = (
+ !in_array($this->ext, array('html', 'htm')) &&
+ in_array($this->ext, array_keys($this->__requestContent))
+ );
- if (!empty($this->ext)) {
- if (in_array($this->ext, array('html', 'htm'))) {
- $this->respondAs('html', array('charset' => Configure::read('App.encoding')));
- } elseif (in_array($this->ext, array_keys($this->__requestContent))) {
- $this->renderAs($controller, $this->ext);
- }
+ if (!empty($this->ext) && $isRecognized) {
+ $this->renderAs($controller, $this->ext);
} elseif ($this->isAjax()) {
$this->renderAs($controller, 'ajax');
+ } elseif (empty($this->ext) || in_array($this->ext, array('html', 'htm'))) {
+ $this->respondAs('html', array('charset' => Configure::read('App.encoding')));
}
if ($this->requestedWith('xml')) {
23 cake/tests/cases/libs/controller/components/request_handler.test.php
View
@@ -253,6 +253,27 @@ function testAutoResponseType() {
$this->assertEqual($this->Controller->ext, '.ctp');
}
+
+/**
+ * testAutoAjaxLayout method
+ *
+ * @access public
+ * @return void
+ */
+ function testAutoAjaxLayout() {
+ $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
+ $this->RequestHandler->startup($this->Controller);
+ $this->assertTrue($this->Controller->layout, $this->RequestHandler->ajaxLayout);
+
+ $this->_init();
+ $this->Controller->params['url']['ext'] = 'js';
+ $this->RequestHandler->initialize($this->Controller);
+ $this->RequestHandler->startup($this->Controller);
+ $this->assertNotEqual($this->Controller->layout, 'ajax');
+
+ unset($_SERVER['HTTP_X_REQUESTED_WITH']);
+ }
+
/**
* testStartupCallback method
*
@@ -692,7 +713,7 @@ function testBeforeRedirectCallbackWithArrayUrl() {
}
/**
- * assure that beforeRedirect with a status code will correctly set the status header
+ * assure that beforeRedirect with a status code will correctly set the status header
*
* @return void
*/
Please sign in to comment.
Something went wrong with that request. Please try again.