1
votes

For now, I don't know it's a bug or a feature? On CakePHP 2.6 when I try use debug() method from basics.php in any controller I'm getting message:

Application error: called handler method exception 'CakeException' with message 'Headers already sent in /Applications/MAMP/htdocs/cakephp26/lib/Cake/basics.php on line 120' in /Applications/MAMP/htdocs/cakephp26/lib/Cake/Network/CakeResponse.php:523 Stack trace: #0 /Applications/MAMP/htdocs/cakephp26/lib/Cake/Network/CakeResponse.php(419): CakeResponse->_sendHeader('HTTP/1.1 200 OK') #1 /Applications/MAMP/htdocs/cakephp26/lib/Cake/Routing/Dispatcher.php(174): CakeResponse->send() #2 /Applications/MAMP/htdocs/cakephp26/app/webroot/index.php(118): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse)) #3 {main}

In earlier versions of CakePHP it was allowed to debug() from other places than views.

1
Then use debug() + die(). You shouldn't let the follow up code run, especially with redirects being tried to send. - mark
Yep, I know, but this is only for development purpose. It's easier put this line for a moment to check something (and later remove it) - then following code should run. It throws an exception event without redirect (the error message in question is only a part, because I'm getting 'Memory exceeded' error finally). Anyway earlier this wasn't problem, so something has changed but it's undocumented? - redd
Don't develop this way. It calles for trouble. If you need the following code to run, use CakeLog::write() etc, logging it away instead of outputting stuff. And yes: github.com/cakephp/cakephp/pull/4106 - mark
@mark this change really breaks a lot of my site. I have many controller functions that use autoRender=false, and output some data with pr(), echo, etc. Now they all raise an exception. It's hard to understand what the exception is though. I'm afraid I'm going to have to downgrade to 2.5.8 in the meantime. I sure hope this gets re-looked at in 2.6.1. - Pyrite

1 Answers

2
votes

I have confirmed that this is a "feature" and is not in 2.5.8, but only in 2.6.0 (at present).

The following code will throw an Exception in 2.6.0, but will not in versions < 2.6.0

public function getposts() {
    $this->autoRender = false;
    $data = $this->Post->query("SELECT * FROM posts");
    pr($data); // or echo json_encode($data);
}

According to the author of this "feature", we now need to add exit() or die() at the end of our methods that use pr(), echo, debug(), etc in controllers now when using >= 2.6.0 and Debug > 0.

Sorry this really isn't an answer, but just wanted to share what I found.