CakePHP debug function


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2.  * Prints out debug information about given variable.
  3.  *
  4.  * Only runs if debug level is greater than zero.
  5.  *
  6.  * @param boolean $var Variable to show debug information for.
  7.  * @param boolean $showHtml If set to true, the method prints the debug data in a screen-friendly way.
  8.  * @param boolean $showFrom If set to true, the method prints from where the function was called.
  9.  * @link http://book.cakephp.org/view/458/Basic-Debugging
  10.  */
  11. function debug($var = false, $showHtml = false, $showFrom = true) {
  12. if (Configure::read() > 0) {
  13. if ($showFrom) {
  14. $calledFrom = debug_backtrace();
  15. echo '<strong>' . substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) . '</strong>';
  16. echo ' (line <strong>' . $calledFrom[0]['line'] . '</strong>)';
  17. }
  18. echo "\n<pre class=\"cake-debug\">\n";
  19.  
  20. $var = print_r($var, true);
  21. if ($showHtml) {
  22. $var = str_replace('<', '&lt;', str_replace('>', '&gt;', $var));
  23. }
  24. echo $var . "\n</pre>\n";
  25. }
  26. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.