Vtiger调试技巧

PHP

  • Turn on log4php.debug library usage, in file config.performance.php
'LOG4PHP_DEBUG' => true,
  • Set the log level, in file log4php.properties
log4php.rootLogger = DEBUG, A1
Note Make sure logs/ folder has write access to apache server process owner.

Database

  • Turn on debugging as adb instanced in include/database/PearDatabase (at end of file)
if(empty($adb)) {
 $adb = new PearDatabase();
 $adb->connect();
 // ADD THIS LINE
 $adb->setDebug(true);
}

Smarty

  • In file, Smarty_setup.php add the following to class constructor function
function vtigerCRM_Smarty() {
 $this->Smarty();
 $this->template_dir = 'Smarty/templates';
 // ...
 // ADD THIS LINE
 $this->debugging = true;
}

PHP Files

  • To print all the SQL commands to the browser

In include/database/PearDatabase.php near line 680

replace:

//$this->database->debug = true;

with:

$this->database->debug = true;
  • To print DEBUG log data to the logfile logs/vtigercrm.log.

In log4php.properties

replace:

log4php.rootLogger=FATAL,A1

with:

log4php.rootLogger=DEBUG,A1
  • To print a value (or array) to the browser, insert the following in the PHP file:
trigger_error('TempDebug: $someVariable="'.print_r($someVariable, TRUE) .'"');

Don’t forget to remove it afterward!

  • Better still, to print an array to the browser in a more legible format we add opening and closing HTML <PRE> tags:
trigger_error('TempDebug: $smallArray=<PRE>"'.print_r($smallArray, TRUE) .'"</PRE>');

Note however that trigger_error() truncates the output if the array is large. The following works on large arrays:

trigger_error('TempDebug: $largeArray:...'); print_r("<PRE>"); print_r($largeArray); print_r("</PRE>");

Smarty Templates

Smarty templates are used to programmatically create HTML pages.

  • To list all the data available to a Smarty template in a separate browser window:

In /Smarty/libs/Smarty.class.php near line 104

replace:

var $debugging       =  false;

with:

var $debugging       =  true;
  • In a Smarty template data can be “printed” into an HTML comment and then viewed by selecting View->Page Source in your browser. This example shows some of the parameters “passed” from PHP code to a Smarty template:

 

AJAX and Javascript

Note Warning: Changes in AJAX code may require matching changes in Smarty code!
  • To print a value (or array) to a brower message box, insert the following in the JavaScript file:
  alert('TempDebug: someVariable = "' +someVariable +'"');
  • A JavaScript debugger is available for Firefox, Mozilla, Netscape [1].

原文链接:http://wiki.vtiger.com/index.php/DebugTechniques