Disable CakePHP debug output when using Ajax

While developing a CakePHP application and debug value set to greater than 0(zero) (development mode) we may want to show our Ajax results clean i.e. without debug information (in form of SQL log etc.) attached to it.

To make the Ajax result clean we may add a few lines of code in our controller’s (AppController in order to take effect globally) beforeFilter function which is resulted to show like the following (In case of AppContoller):

< ?php
class AppController extends Controller {
var $components = array('RequestHandler');
var $helpers = array('Html','Form','Ajax');
function beforeFilter() {
if ( $this->RequestHandler->isAjax() ) {
Configure::write('debug',0);
}
}
}
?>

Note that while this will disable the debugging output, it will also have other affects too (for the life of the Ajax Request) like extending the length of time that the “schema” is cached. This should make little or no difference, but is worth remembering (Thanks to Ryan, trying to find it how and why :().

3 thoughts on “Disable CakePHP debug output when using Ajax

  1. Thanks for this useful information, I was struggling with this problem for my entire day.

    Cheers
    Surya

Leave a Reply