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>’;
print_r($array);
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>’;
print_r($array);
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…
Happy Coding
I am new to opencart and and php.
I need a more specific example.
this->debug($array);
where do you put this code.