extension joomla, template joomla,banner extension joomla,jomla slider,slider joomla
Debug() function for Opencart

Have you wondered if a single function call would be sufficient to output the array in pre-formatted way. I have been working with opencart for some months and I realize how repititive is it to repeat same lines of code to make array look nice. By the way, I am a big fan of CakePHP framework and its powerful debugging technique.

echo ‘<pre>’;
echo </pre>;

Whenever I need to echo any array, I needed to repeat the “pre” so that I get readable array.
So, I thought of making a global function debug(), so that it takes array as argument and prints the array in a nice format.

For this, there is a need for making a global function, so that we can access this function whenever we require, like


The debug function was added in the abstract class Controller after render() function at system/engine/controller.php and if you need it for model , system/engine/model.php.

public function debug($array){
// show calling url : Line line_number
$bt = debug_backtrace();
$caller = array_shift($bt);
echo ‘<b>’.$caller[‘file’].’ : Line ‘.$caller[‘line’].'</b>’;

echo ‘<pre>’;
echo ‘</pre>’;
return true;
I don’t think the core modification is a good idea, but if it can make your life easier, then why not…

Smile Happy Coding Smile

Related Article

destination source:https://www.programming-techniques.com/2013/01/debug-function-for-opencart.html