Skip to content

Commit

Permalink
Remove turning off auto rendering when action is called through reque…
Browse files Browse the repository at this point in the history
…stAction().

You should return a response instance from the action to avoid auto rendering.
  • Loading branch information
ADmad committed Oct 12, 2014
1 parent 68b6628 commit 7115cbe
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
10 changes: 4 additions & 6 deletions src/Controller/Controller.php
Expand Up @@ -384,12 +384,6 @@ public function setRequest(Request $request) {
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;
}
}

/**
Expand Down Expand Up @@ -577,6 +571,10 @@ public function setAction($action) {
* @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;
Expand Down
Expand Up @@ -31,6 +31,7 @@ public function index() {

public function some_method() {
$this->response->body(25);
return $this->response;
}

}
Expand Up @@ -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;
}
}
15 changes: 10 additions & 5 deletions tests/test_app/TestApp/Controller/RequestActionController.php
Expand Up @@ -77,30 +77,33 @@ public function return_here() {
*/
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([
Expand All @@ -109,12 +112,13 @@ public function params_pass() {
'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;
Expand All @@ -123,12 +127,13 @@ public function param_check() {
$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'));
Expand Down
3 changes: 2 additions & 1 deletion tests/test_app/TestApp/Controller/SessionTestController.php
Expand Up @@ -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 change: 1 addition & 0 deletions tests/test_app/TestApp/Controller/TestsAppsController.php
Expand Up @@ -37,6 +37,7 @@ public function index() {

public function some_method() {
$this->response->body(5);
return $this->response;
}

public function set_action() {
Expand Down

0 comments on commit 7115cbe

Please sign in to comment.