Browse Source

Remove turning off auto rendering when action is called through requestAction().

You should return a response instance from the action to avoid auto rendering.
ADmad 11 years ago
parent
commit
7115cbeb20

+ 4 - 6
src/Controller/Controller.php

@@ -384,12 +384,6 @@ class Controller implements EventListener {
 		if (isset($request->params['pass'])) {
 			$this->passedArgs = $request->params['pass'];
 		}
-		if (!empty($request->params['return']) && $request->params['return'] == 1) {
-			$this->autoRender = false;
-		}
-		if (!empty($request->params['bare'])) {
-			$this->getView()->autoLayout = false;
-		}
 	}
 
 /**
@@ -577,6 +571,10 @@ class Controller implements EventListener {
  * @link http://book.cakephp.org/2.0/en/controllers.html#Controller::render
  */
 	public function render($view = null, $layout = null) {
+		if (!empty($this->request->params['bare'])) {
+			$this->getView()->autoLayout = false;
+		}
+
 		$event = $this->dispatchEvent('Controller.beforeRender');
 		if ($event->result instanceof Response) {
 			$this->autoRender = false;

+ 1 - 0
tests/test_app/Plugin/TestPlugin/src/Controller/TestsController.php

@@ -31,6 +31,7 @@ class TestsController extends TestPluginAppController {
 
 	public function some_method() {
 		$this->response->body(25);
+		return $this->response;
 	}
 
 }

+ 2 - 1
tests/test_app/TestApp/Controller/OrangeSessionTestController.php

@@ -38,9 +38,10 @@ class OrangeSessionTestController extends Controller {
 /**
  * session_id method
  *
- * @return void
+ * @return \Cake\Network\Session
  */
 	public function session_id() {
 		$this->response->body($this->Session->id());
+		return $this->response;
 	}
 }

+ 10 - 5
tests/test_app/TestApp/Controller/RequestActionController.php

@@ -77,30 +77,33 @@ class RequestActionController extends AppController {
  */
 	public function paginate_request_action() {
 		$data = $this->paginate();
+		$this->autoRender = false;
 	}
 
 /**
  * post pass, testing post passing
  *
- * @return array
+ * @return \Cake\Network\Reponse
  */
 	public function post_pass() {
 		$this->response->body(json_encode($this->request->data));
+		return $this->response;
 	}
 
 /**
  * query pass, testing query passing
  *
- * @return array
+ * @return \Cake\Network\Reponse
  */
 	public function query_pass() {
 		$this->response->body(json_encode($this->request->query));
+		return $this->response;
 	}
 
 /**
  * test param passing and parsing.
  *
- * @return void
+ * @return \Cake\Network\Reponse
  */
 	public function params_pass() {
 		$this->response->body(json_encode([
@@ -109,12 +112,13 @@ class RequestActionController extends AppController {
 			'url' => $this->request->url,
 			'contentType' => $this->request->env('CONTENT_TYPE'),
 		]));
+		return $this->response;
 	}
 
 /**
  * param check method.
  *
- * @return void
+ * @return \Cake\Network\Reponse
  */
 	public function param_check() {
 		$this->autoRender = false;
@@ -123,12 +127,13 @@ class RequestActionController extends AppController {
 			$content = 'return found';
 		}
 		$this->response->body($content);
+		return $this->response;
 	}
 
 /**
  * Tests session transmission
  *
- * @return void
+ * @return \Cake\Network\Reponse
  */
 	public function session_test() {
 		$this->response->body($this->request->session()->read('foo'));

+ 2 - 1
tests/test_app/TestApp/Controller/SessionTestController.php

@@ -38,9 +38,10 @@ class SessionTestController extends Controller {
 /**
  * session_id method
  *
- * @return void
+ * @return \Cake\Network\Response
  */
 	public function session_id() {
 		$this->response->body($this->Session->id());
+		return $this->response;
 	}
 }

+ 1 - 0
tests/test_app/TestApp/Controller/TestsAppsController.php

@@ -37,6 +37,7 @@ class TestsAppsController extends AppController {
 
 	public function some_method() {
 		$this->response->body(5);
+		return $this->response;
 	}
 
 	public function set_action() {