Tuesday, July 30, 2013

Debug Code in Drupal

Simple using print_r or var_export , you can debug code within Drupal.

$node = node_load(123);

Drupal devel module provides dsm and dpm functions to debug code within drupal.

$node = node_load(123);

drupal latest version provides debug inbuilt function to print errors, notices and warnings as well.This could be in the page or in the logs depending on how php is configured.
For example,

$node = node_load(123);

The full options for debug function are:
debug($data, $label, $print_r);

The $data is pretty self explanatory. It can be anything you could pass
through print_r or var_export. The $label allows for a custom label to be
added. This is ideal when you are sending the information to a log and you
want a key to search the logs for. The 3rd argument is whether to use print_r
or var_export. The default is var_export. If you are interested between the
two I’d suggest reading the manual pages.

No comments:

Post a Comment