Sunday, December 21, 2014

Debug helper

codeigniter debug helper

Code

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); if ( ! function_exists('printr')) { function printr($var) { $CI =& get_instance(); echo '<pre>' . print_r($var, TRUE) . '</pre>'; } } if ( ! function_exists('vardump')) { function vardump($var) { $CI =& get_instance(); echo '<pre>'; var_dump($var); echo '</pre>'; } } /* End of file debug_helper.php */ /* Location: ./application/helpers/debug_helper.php */

Description

This is a little helper functions for debugging your CodeIgniter application. This helper contains the following functions:
  • printr (for print_r())
  • vardump (for var_dump())

Usage

Load a helper into your controller:
$this->load->helper('debug');
printr()
Print your array in readable format - with usage of print_r():
printr($myarray);
The function will print print_r($myarray) with PRE tags to make the output readable.
vardump()
Print readable dump information about your variable - with usage of var_dump():
vardump($myvar);
The function will print vardump($myvar) with PRE tags to make the output readable.

Useful link : codeigniter-debug-helper
 CodeIgniter Debug helper v1.2.0