Browse Source

Use config key instead of public property for ajax layout setting.

ADmad 12 years ago
parent
commit
06370f8b4b

+ 8 - 10
src/Controller/Component/RequestHandlerComponent.php

@@ -39,14 +39,6 @@ use Cake\Utility\Xml;
 class RequestHandlerComponent extends Component {
 
 /**
- * The layout that will be switched to for Ajax requests
- *
- * @var string
- * @see RequestHandler::setAjax()
- */
-	public $ajaxLayout = 'ajax';
-
-/**
  * Determines whether or not callbacks will be fired on this component
  *
  * @var boolean
@@ -87,11 +79,17 @@ class RequestHandlerComponent extends Component {
  *
  * These are merged with user-provided config when the component is used.
  *
+ * - `checkHttpCache` - Whether to check for http cache.
+ * - `viewClassMap` - Mapping between type and view class.
+ * - `ajaxLayout` - The layout that will be switched to for Ajax requests.
+ *   See RequestHandler::setAjax()
+ *
  * @var array
  */
 	protected $_defaultConfig = [
 		'checkHttpCache' => true,
-		'viewClassMap' => ''
+		'viewClassMap' => '',
+		'ajaxLayout' => 'ajax'
 	];
 
 /**
@@ -510,7 +508,7 @@ class RequestHandlerComponent extends Component {
 		$options = array_merge($defaults, $options);
 
 		if ($type === 'ajax') {
-			$controller->layout = $this->ajaxLayout;
+			$controller->layout = $this->_config['ajaxLayout'];
 			return $this->respondAs('html', $options);
 		}
 

+ 1 - 1
tests/TestCase/Controller/Component/RequestHandlerComponentTest.php

@@ -99,7 +99,7 @@ class RequestHandlerComponentTest extends TestCase {
 		$controller = $this->getMock('Cake\Controller\Controller');
 		$collection = new ComponentRegistry($controller);
 		$requestHandler = new RequestHandlerComponent($collection, $config);
-		$this->assertEquals('test_ajax', $requestHandler->ajaxLayout);
+		$this->assertEquals('test_ajax', $requestHandler->config('ajaxLayout'));
 		$this->assertEquals(array('json' => 'MyPlugin.MyJson'), $requestHandler->config('viewClassMap'));
 	}