Extension Development, Debugging
<< Back to Extension Development page
Contents |
Tipps on debugging
Debug TYPO3
See also the XDG
- In typo3conf/localconf.php, set [FE][debug] = 1 and [SYS][devIPmask] to e.g. "192.*,169.*,127.0.0.1". Then use the extended debug() function of the Extension cc_debug. On your TYPO3 site you will see a bomb ([[1]]) in the upper right corner if there is debug output by the currently running PHP script.
// show the variable together with the line number and file name debug($variable, 'Variable name/description', __LINE__, __FILE__);
Alternatively you can use the extension beko_debugster or fh_debug. These will also work if there are HTML or JavaScript errors on a page.
// display the variable debugster($variable, 'Variable name/description');
// show the stack trace of the current function $tmp = t3lib_div::debug_trail(); debug($tmp, 'stack trace in className::methodName', __LINE__, __FILE__); // Replace 'className' with the name of the class and 'methodName' with the name of the method from where you call <tt>debug()</tt>. // If you want to add devLog functionality to your applications, simply write lines like this: if (TYPO3_DLOG) t3lib_div::devLog('some message', 'extension key'); // …if you want debug data use this if (TYPO3_DLOG) t3lib_div::devLog('some message', 'extension key', 0, $dataArray);
The devlog - extension provides development logging/debugging functionality for usage with t3lib_div::devlog(). The t3lib_div::devlog() function itself provides only an interface for logging but no implementation.
rlmp_filedevlog logs messages from t3lib_div::devlog() calls into a text file, by default to debug.log of your web server home directory, e.g. at /var/www/html/.
Do not forget to allow write access for the httpd user. You have to activate devlog by adding the following line to typo3conf/localconf.php:
$TYPO3_CONF_VARS['SYS']['enable_DLOG'] = true;
error_log()
You can write to the (system) error log using:
error_log('text', 0); error_log('postition A: $content='.$content, 3, '/usr/local/htdocs/typo3/error_log');
and view the entries of the log file. (Linux: /var/log/messages, /var/log/apache2/error_log or /var/log/httpd/error_log).
You can modify the error_log = syslog settings in /etc/php.ini.
If you supply a third parameter to error_log(), it will write that log entry to this file only.
To show the contents of arrays, you use foreach loops:
foreach ($menuItems as $key => $menuItem) { if (is_array($menuItem)) { error_log ('-- tx_commerce_cm1 menuItem['.$key.'] --', 0); foreach ($menuItem as $k1=>$v1) { error_log ('['.$k1.']='.$v1,0); } } else { error_log ('-- tx_commerce_cm1 menuItem['.$key.'] = '.$menuItem, 0); } }
Or use these lines with var_dump():
ob_start(); print_r($myComplexArray); $debugOut = ob_get_contents(); ob_end_clean(); error_log ('$myComplexArray = '.$debugOut);
How to debug SQL
$GLOBALS['TYPO3_DB']->store_lastBuiltQuery = true; $GLOBALS['TYPO3_DB']->exec_UPDATEquery( 'xxx', 'yyy', 'zzz'); t3lib_div::devLog('[write message in english here]'.$GLOBALS['TYPO3_DB']->debug_lastBuiltQuery , 'extension key');
Use T3Ext:debug_mysql_db to debug SQL queries, measure query execution time and hide unnecessary PHP warning messages.
How to debug TypoScript
At the end of the table you will see three stdWrap options which enable various debug modes:
- debug boolean
Passes output through htmlspecialchars(). Useful for debugging which value stdWrap actually ends up with while you're constructing a website with TypoScript.
- debugFunc boolean
Prints the content using the debug() function. Set to value "2" (well, it's not *quite* a boolean;)) the content will be printed in a table - looks nicer. Example:
marks.MENU_TITLE = TEXT marks.MENU_TITLE.field = title marks.MENU_TITLE.stdWrap.debugFunc = 2 marks.MENU_TITLE.stdWrap.wrap = title at position 1 |
- debugData boolean
Prints the current data-array, $cObj->data, directly to browser. This is where ".field" gets its data from.
A trick that's extremely useful while developing is simply build an extension template (+ext) for the specific page you want to debug; so that you can manipulate your TypoScript code as you want without affecting other pages. Once you've finished debugging, delete the extension template.
- debugItemConf boolean
Outputs the configuration arrays for each menu item, using the debug()-function. Useful to debug optionSplit things and such. Applies to GMENU, TMENU, IMGMENU.
An example:
temp.L2menuItems = HMENU temp.L2menuItems.entryLevel = 1 temp.L2menuItems.1 = TMENU temp.L2menuItems.1.debugItemConf = 1