What more frustrating than not knowing what is going on when a drupal page is loading?
There are often redirection pages containing errors we can't see.
When developing a module or building a theme, it would be useful to know what content there is in some variables.
So what does drupal offer for this? A drupal_set_message('<pre>'.print_r($variable, true).'</pre>');? Isn't this a bit too long?
Well, the Devel module, specifically designed to make the development of module and drupal administration easier, bring up some awesome functions:
1
| dsm($input, $name = NULL); |
alias of drupal_set_message, put the input variable in a dropdown style with the Krumo library
$input: your variable or your text
$name: (optional) prefix of the message (e.g. : dsm('my content', 'my variable'); will display "my variable => my content")
1
| dpm($input, $name = NULL); |
alias of dsm()
1
| dvm($input, $name = NULL); |
same as dsm() but using var_dump() (e.g. : dvm('my content'); will display "string(10) "my content")
1
| dpr($input, $return = FALSE, $name = NULL); |
display the print_r() of your argument at the beginning of the page or store it in a variable (useful if the message section is not displayed in any region of the theme)
$return: if TRUE, print_r() of the input will be returned
1
| kpr($input, $return = FALSE, $name = NULL); |
same as dpr() but will display with Krumo library
1
| dvr($input, $return = FALSE, $name = NULL); |
same as dpr() but using var_dump()
And others not concerning variable display :
display arguments passed to the current function
$always: if FALSE, will only display once
display the complete SQL query and the error in the browser (useful to know what arguments are passed to the query)
display arguments in the Firebug console if FirePHP is installed
All these useful functions are hardly documented, so if you find others: share it ! 