понедельник, 4 июля 2011 г.

Отладка друпала

В главной папке сайта создаем файлик debug.php следующего содержания : 

<?php
/**
 * Save any output to file
 *
 * @param any_type $variable
 * @param string $comment
 */
function ___save_debug($variable, $comment = NULL) {
  $fp = @fopen('__dbg.txt', 'a');
  if( is_array($variable) || is_object($variable) ) {
    $variable = print_r($variable, true);
  }
  $tmp = $comment." : ".$variable."\n\n===========================\n";
  fwrite($fp, $tmp);
  fclose($fp);
}

/**
 * Returns print version of variable.
 * Put result on the top of the page.
 *
 * @param any_type $variable
 * @param string $comment
 */
function ___print_debug($variable, $comment = NULL) {
  $print_var = print_r($variable, true);
  drupal_set_message('<p><strong>'.$comment.'</strong></p><pre>'.$print_var.'</pre>');
}
?>

в index.php добавляем

require_once './debug.php';

То есть, он начнет выглядеть следующим образом:

require_once './includes/bootstrap.inc';
require_once './debug.php';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$return = menu_execute_active_handler();
........