var_dump(), print_r() are commonly used functions to display data that is passed across controllers or views when playing in MVC frameworks. As the printed data stretches as a long string, it may be difficult to manipulate the resultset in most cases.
When programming in CakePHP or CodeIgniter or other MVC frameworks when you do not want to turn on the debugger routine and want to have a clean display of Array Data you can try adding a simple method in the Controller (appController in cakePHP) as follows
function testdata($passed_data_array){
echo "<pre>";
print_r($passed_data_array);
echo "</pre>";
}
Usage of “pre” HTML tag preserves the spaces, line breaks and renders a neat display of array data.
You can also use var_dump instead of print_r depending on your need in the above method.
CakePHP’s wrapper method: pr(mixed $var) is the equivalent of the above method.
Tags: cakePHP, codeigniter, MVC, pre HTML tag, print array data, print_r, var_dump





CakePHP has the ‘debug()’ function which displays the line at which it was called and styling in addition to the dump of objects, vars, arrays, etc.
Instead of building your own functions, first try to find framework solutions to your problems.
Personally, I prefer using pr() or print_r() for quick debugging rather than debug().