Displaying debug output
Primary tabs
Introduction
In the previous tutorial we implemented some basic coding in the content's .tpl.php and template.php files. Now as soon as you enter code you will be prone to making accidental mistakes, in fact there was one in the previous tutorial did you spot it? Now if something goes wrong it's not necessary to go off and have a cup of tea. Drupal provides methods of outputting data to your display and we are going to visit some of those methods to demonstrate how they can help.
We will use the the image field pager tutorial for our examples to demonstrate how this may be useful for any development you may be undertaking. I'll also disable the main output to the page to highlight the debug outputted.
Modules
You will need to install the devel module to be able to call all the debug output methods.
Methods
print_r
This is an old trusted favorite which many professionals still use and are happy with. Now if this insert this command
<?php print_r($build); ?>
This will be the output

This is showing both our data array's including the images and pager at the bottom but there is some debug output to see what is going on.
Methods provided by the devel module
The devel module provides a number of debug methods to use as alternatives lets look at some of them. For reference these can be found in the devel.module file from the devel module.
DPM
This prints a variable to the 'message' area of the page. This also includes the Krumo strings, integers and such
I'll use this command
<?php dpm($build); ?>
This will be the output at the top of the content
![]()
This can be expanded to

For a developer this is more useful as well as displaying the contents of both arrays it also displays the line of code from where the DPM function is called from.
DVM
Using this command
<?php dvm($build); ?>
This will be the output

Again it shows both the arrays but without the krumo variables that were included dpm() function there is less information provided.
DEBUG
Using this command
<?php debug($build); ?>
This will be the output

This may show up in your log file instead of display, you can select the settings from configuration -> development -> logging and errors section. The debug function is provided in Drupal 7 by default where as the above functions need to have the devel module installed.
Conclusion
You have now seen a number of ways of displaying debug data and of course it is your preference on deciding which one to use. Note in regards to the methods supplied by the devel module we are only just touching the surface on what it provides, check out devel.module to see what I mean.
That's all for this one folks, and don't forget to flush your cache.
Latest Updates
Recent comments
Recent Tweets
- New post: Posting location co-ordinates to a drupal service - Part 2 http://t.co/MQhlVKBNKC — 1 month 4 days ago
- New post: Posting location co-ordinates to a drupal service - Part 1 http://t.co/2xlYgqFaJ0 — 1 month 5 days ago
- New post: Connecting a drupal service with a mobile application - Part 2 http://t.co/01cFtAunDs — 1 month 5 days ago
- New post: Using drupal services to connect to mobile applications - Part 1 http://t.co/VEURftHCef — 1 month 5 days ago
- New post: Creating Drupal 7 video gallery http://t.co/HvpKU7uT — 3 months 1 week ago









Add new comment