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
).
Possibly Related posts:
- Creating Ajax form in Cakephp using jQuery
Because of its being more flexible, extensible and precise nature the jQuery certainly has emerged as a more popular Javascript library as compared to prototype... - How to apply search filters in cakephp ajax pagination
Sometimes we need to filter records via custom query while using ajax pagination in a cakephp application. An easy way to achieve this is to... - Creating Ajax form in Cakephp (with Prototype.js)
(If you are using jQuery with cakephp you may want to view this article, Creating Ajax form in Cakephp using jQuery ) With the help... - Cakephp important facts you must know – Part 3
You load a plugin model like this: $this->loadModel(“Forum.Topic”) You output requestAction result using $this->requestAction(array(‘controller’ => ‘articles’, ‘action’ => ‘featured’), array(‘return’)); // see array(‘return’) In controller,... - A simple way to debug a php application in production mode
How to debug a live website built in php? Here’s a basic, simple and custom method i usually use to debug live or production web...
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.






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