Debug application in cakephp

First of all we have to know what is debugging.

Debugging is the most essential part of Software development life cycle. Its really harder to define debug in just single line. But following are the basic necessity of debugging.

  • Trace incoming or outgoing data
  • Trace flow of application
  • View error generated by the application.
  • A editor can take important role while debugging the application.For this special configuration is necessary.

CAKEPHP DEBUG CONFIGURATION BASICS

CakePHP comes handy if we consider its debugging facility.Following are the two important files which contains code for cakephp debugging.

  • config/core.php
  • config/bootstrap.php

In cakePHP’s core.php contains code like

Configure::write('debug', 2);

Here debug can be 3 types and of  value means,

  • for 2, It will show all the Error in browser in details. Even it can show the details SQL releated errors and Query.
  • for 1, It will show only just basic part of the error rather entire description about the error
  • for 0, It will disable the debugging facility.It will not show any warning , error or messages.

In cakePHP’s bootstrap.php contains code like

App::uses('CakeLog', 'Log');
CakeLog::config('debug', array(
    'engine' => 'FileLog',
    'types' => array('notice', 'info', 'debug'),
    'file' => 'debug',
));

Above code tells cakePHP where to store debugging information. Usually its file based storage.In more simpler i can say, cakePHP will store all the debugging information inside a text file in tmp directory of cakePHP installation directory.

HOW TO USE DEBUGGING IN CAKEPHP

debug() function is used to debug codes in cakephp.

Its globally available and it can be used any where and any class of cakephp.

It works similar to print_r and var_dump functions of Core PHP.

following are the example of how to use debug() function in cakephp

Class Bikash extends appController{
  public function index(){
    debug($this->data);
  }
}

debug() function can accept 3 parameters

  1. First parameter is the variable itself to debug
  2. Second parameter is the True or false (null) , whether to render HTML based or not
  3. Third parameter is used whether to show request comes from, like in above example, i am debugging from Bikash controller. show debug function will show request is coming from BikashController.

Keep Debugging. :)