浏览代码

update ajax view

Stefan Dickmann 12 年之前
父节点
当前提交
ff7de7c1b5
共有 4 个文件被更改,包括 35 次插入2 次删除
  1. 1 2
      Controller/Component/CommonComponent.php
  2. 20 0
      Test/Case/View/AjaxViewTest.php
  3. 1 0
      Test/test_app/View/Items/index.ctp
  4. 13 0
      View/AjaxView.php

+ 1 - 2
Controller/Component/CommonComponent.php

@@ -95,8 +95,7 @@ class CommonComponent extends Component {
 			// The header can be read with JavaScript and a custom Message can be displayed
 			$this->Controller->response->header('X-Ajax-Flashmessage', json_encode($ajaxMessages));
 
-			// AJAX debug off
-			Configure::write('debug', 0);
+			$this->Session->delete('messages');
 		}
 
 		// Custom options

+ 20 - 0
Test/Case/View/AjaxViewTest.php

@@ -109,4 +109,24 @@ class AjaxViewTest extends CakeTestCase {
 		$this->assertTextEquals($expected, $result);
 	}
 
+	/**
+	 * AjaxViewTest::testWithoutSubdir()
+	 *
+	 * @return void
+	 */
+	public function testWithoutSubdir() {
+		$Request = new CakeRequest();
+		$Response = new CakeResponse();
+		$Controller = new Controller($Request, $Response);
+		$View = new AjaxView($Controller);
+		$View->viewPath = 'Items';
+		$View->subDir = false;
+		$result = $View->render('index');
+
+		$this->assertSame('application/json', $Response->type());
+		$expected = array('error' => null, 'content' => 'My Index Test ctp');
+		$expected = json_encode($expected);
+		$this->assertTextEquals($expected, $result);
+	}
+
 }

+ 1 - 0
Test/test_app/View/Items/index.ctp

@@ -0,0 +1 @@
+My Index Test ctp

+ 13 - 0
View/AjaxView.php

@@ -17,6 +17,16 @@ App::uses('View', 'View');
 class AjaxView extends View {
 
 	/**
+	 * List of variables to collect from the associated controller.
+	 *
+	 * @var array
+	 */
+	protected $_passedVars = array(
+			'viewVars', 'autoLayout', 'ext', 'helpers', 'view', 'layout', 'name', 'theme',
+			'layoutPath', 'viewPath', 'request', 'plugin', 'passedArgs', 'cacheAction', 'subDir'
+	);
+
+	/**
 	 * The subdirectory. AJAX views are always in ajax.
 	 *
 	 * @var string
@@ -41,6 +51,9 @@ class AjaxView extends View {
 		if ($this->layout === 'default' || $this->layout === 'ajax') {
 			$this->layout = false;
 		}
+		if ($this->subDir === null) {
+			$this->subDir = 'ajax';
+		}
 
 		if (isset($controller->response) && $controller->response instanceof CakeResponse) {
 			$controller->response->type('json');