While trying to debug a variable in PHP i love the var_dump() method. Off course i have debugger tools like xDebug enabled in my IDE i love using var_dumps. One of the thing i like about var_dump is it gives the complete structure of an object at that instance. Using MVC model for PHP usually ties you up with a framework and a choice of view. For Zend it is smarty which i use, and smarty is not straight forward to debug like PHP. After some research i found out various ways to use var_dump. Here are they:
Method 1:
{php}
$var = $this->get_template_vars('var');
var_dump($var);
{/php}
Using php tags is not good practice and ideally they should be disabled for security reasons anyway
Method 2:
{$var|@print_r}
It only outputs the values and not the keynames, and there are no spaces between the values, so it’s not ideal for debugging.
Method 3:
{$var|@var_dump}
Method 4:
{debug}
just use debug in your .tpl and look at your sourcecode
Method 5:
{$varname|@debug_print_var}
Few of these methods are taken from StackOverflow. If you know more do comment or cite them. Will update the list.





















[…] Debugging in Smarty template […]