Hidden Devel functions

What more frustrating than not knowing what is going on when a drupal page is loading? angry 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? indecision

Well, the Devel module, specifically designed to make the development of module and drupal administration easier, bring up some awesome functions:

dsm($input, $name = NULL);

alias of drupal_set_message, put the input variable in a dropdown style with the Krumo library
your variable or your text
$name: (optional) prefix of the message (e.g. : dsm('my content', 'my variable'); will display "my variable => my content")

dpm($input, $name = NULL);

alias of dsm()

dvm($input, $name = NULL);

same as dsm() but using var_dump() (e.g. : dvm('my content'); will display "string(10) "my content")

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

kpr($input, $return = FALSE, $name = NULL);

same as dpr() but will display with Krumo library 

dvr($input, $return = FALSE, $name = NULL);

same as dpr() but using var_dump()

And others not concerning variable display :

dargs($always = TRUE);

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)

dfb($arg, ...);

display arguments in the Firebug console if FirePHP is installed

All these useful functions are hardly documented, so if you find others: share it ! wink

Subscribe to RSS - 6.x