zen of coding

Bye-bye $cakeDebug…

The infamous $cakeDebug variable, which has been around for a long time and managed to annoy a few people in the process, has been replaced in the recent builds of CakePHP 1.3 with an element.

See the ticket here:
http://cakephp.lighthouseapp.com/projects/42648/tickets/35-the-implementation-of-dbo_sourcephp-logging-needs-changed

The two points to take away are:

  1. Automatic SQL dumps have been removed from DboSource
  2. If you wish to display SQL dumps, as before… replace any occurrence of $cakeDebug in your layouts with echo $this->element(‘sql_dump’);

One of the obvious benefits, is that you no longer have to tweak the core to take control of the SQL debug. As always, simply place sql_dump.ctp in your own app (i.e. app/views/elements) and do what you wish with the output.

Just to test things out let’s throw the SQL debug into the Firebug console, rather than directly into the view.

We’ll need to modify the sql_dump.ctp (which now has been copied into our own app), just a little bit.

Around line 35, let’s replace the default output for SQL dump, for something like this:

//unchanged part of the sql_dump.ctp above this line

//here we are outputting the queries into the Firebug console
foreach($logs as $source => $logInfo) {
  foreach($logInfo['log'] as $key => $query) {
    echo $this->Html->scriptBlock('console.log("' . $query['query'] . '")');
  }
}

For the real world example, this may not be a reasonable thing to do by any means… but it does show how easy it is now to output the SQL debug wherever you need it (logging, debugging, stylizing, parsing, sending to some remote destination… up to your imagination really).

%d bloggers like this: