How to debug code in Drupal?

Answer

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

  $node = node_load(123);
print_r($node);
?>

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

  $node = node_load(123);
dpm($node);
?>

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);
debug($node);
?>

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.

All drupal Questions

Ask your interview questions on drupal

Write Your comment or Questions if you want the answers on drupal from drupal Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---