Category Archives: Functions

Requiring files in Drupal 6 & 7

I have seen a lot of Drupal modules where requiring php files is done like this

$module = 'my_module';
require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . '/test.php');

While this is totally right i still encourage you to use special function for this called “module_load_include“.

module_load_include('php', 'my_module', 'test');

Logging in Drupal 7

In case you need to log errors and other messages  in Drupal 7 use may use it’s watchdog function. Same thing will work for Drupal 6.

watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL)

Example with some data:

watchdog('Booking', 'Sucessfully booked for %persons', array('%persons' => 5), WATCHDOG_INFO);

Some possible severity levels are WATCHDOG_EMERGENCY, WATCHDOG_ALERT, WATCHDOG_CRITICAL, WATCHDOG_ERROR, WATCHDOG_WARNING, WATCHDOG_NOTICE, WATCHDOG_INFO, WATCHDOG_DEBUG.

Read more from Drupal 7 documentation