Extension Development

From TYPO3Wiki

Jump to: navigation, search

<< Back to Developer manuals page

[edit]

You find all the different extension development manuals either by the extensions themself or in the TYPO3 documentation matrix.

Contents

Development Mini-HOWTO

This is a small HowTo showing you how to start developing for TYPO3.

External resources

Documentation

Image:ExtDevEvalLinks.png

Debug TYPO3

See also the XDG

  • Enable [FE][debug] = 1 and set the [SYS][devIPmask] (e.g. = 192.*,169.*,127.0.0.1). Then use the extended debug() function of the Extension cc_debug. On your TYPO3 homepage you will get a bomb

CC-Debug.png in the upper right corner if there is a debug information in the currently running PHP script.

<PHP> :
 
# gives you the output of the variable together with the line number and file name.
 
debug ($variable, 'Output of variable', __LINE__, __FILE__); 
 
<PHP> :
 
# Gives you the list of functions and files from where it has been called.
$tmp = t3lib_div::debug_trail();
debug ($tmp, 'calling path in className::methodName', __LINE__, __FILE__);
 
<PHP> :
 
 # If you want to implement the devLog in your applications: 
 t3lib_div::devLog 
 
 #simply add lines like:
 if (TYPO3_DLOG) t3lib_div::devLog('[write message in english here]', 'extension key');
 

The cc_devlog - extension provides development logging/debugging functionality for the usage of 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 apache home directory, e.g. at /var/www/html/.
Do not forget to give it write access for the apache httpd user.

You have to activate devLog by putting this line into your typo3conf/localconf.php file. <PHP> :
 
$TYPO3_CONF_VARS["SYS"]["enable_DLOG"] = '1';
 
<PHP> :
 
 # 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 the

<PHP> :
 
 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). Or modify the 'error_log = syslog' settings in /etc/php.ini .
If you use error_log with a third parameter then this will be the error_log file for this case only.

To show the contents of arrays you use foreach loops: <PHP> :
 
 
 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();
 var_dump($myComplexArray);
 $debugOut = ob_get_contents();
 ob_end_clean();
 error_log ('$myComplexArray = '.$debugOut);
 

debug TypoScript

see TSref section stdWrap

At the end of the table you will see three stdWrap options which let you enter in debug mode :

  • debug boolean
Prints content with HTMLSpecialChars() and
???
: Usefull for debugging which value stdWrap actually ends up with, if you're constructing a website with TypoScript.

Should be used under construction only.


  • debugFunc boolean

Prints the content directly to browser with the debug() function. Should be used under construction only. Set to value "2" the content will be printed in a table - looks nicer.


  • debugData boolean

Prints the current data-array, $cObj->data, directly to browser. This is where ".field" gets data from. Should be used under construction only.

IMHO in order to not affect other pages, simply build a +ext template for the specific page you want to debug so that you can manipulate you typoscript code as you want. Once it's tuned, delete the +ext template.

Get the source code

Classes and functions

  • global $TSFE (or $GLOBALS["TSFE"]), the main front end class, can be found in tslib\class.tslib_fe.php
  • Use parseFunc to convert text from input to disallow HTML tags or allow only those the from the allowTags setting. See parseFunc
if (is_array($this->conf["parseFunc."]))	{
$markerArray["###PRODUCT_NOTE###"] = 
$this->cObj->parseFunc($markerArray["###PRODUCT_NOTE###"],$this->conf["parseFunc."]); 
}

Flexforms

  • If you wish to use flexforms in your extension, follow the Using Flexforms guide.

Multiple Languages

  • Create XML language files to support multiple languages. Use the locallang-XML translation tool to convert php language files into XML and do some cleanings.
  • Create overlay tables which contain only the fields which need translations. Use the Table Library to create SQL queries which hides the language overlay tables to the developer.

Unix

  • Use this command line to search for a pattern in many files under Linux
cd directory-of-sources
find . -name '*.php' -exec grep -ni 'your search string' {} \; -ls
  • Or, "man grep" and see if your installed grep can do something like:
grep -rniH --include '*php' 'your search string' directory-of-sources

Database

  • Database Abstraction Layer - DBAL

To activate the writing of error messages when one of your database accesses fails, open the file typo3/t3lib/class.t3lib_db.php and change the line

// Debug:
var $debugOutput = FALSE;		// Set "TRUE" if you want database errors outputted.

to

// Debug:
var $debugOutput = TRUE;

To get detailed infos about the created SQL command you make an error_log entry into the function, e.g. SELECTquery.
The following change will write all the created database statements into the error_log file:

function debug($func)	{
error_log ($this->debug_lastBuiltQuery, 0);

In the Install Tool 'All Configuration' set

[SYS][sqlDebug] = 1 // Boolean. If set, then database queries that fails are outputted in browser. For development.

Or in typo3conf/localconf.php or somewhere in the code of your extension:

$TYPO3_CONF_VARS['SYS']['sqlDebug'] = 1;

Variables

  • access the global variables, e.g.
global $BE_USER, $LANG, $BACK_PATH, $TYPO3_CONF_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS;

Use libraries and APIs

please add the ones you like. --Daniel Brüßler 11:03, 4 June 2007 (CEST)

Caching issues

  • Generally you have to use the extension variable like 'tx_myext_pi_name[variable]'.
  • You can also define standalone parameters e.g. for 'begin_at', 'offset' and similars for which the cHash parameter will get created using these functions:
tslib_pibase::pi_getPageLink
t3lib_div::cHashParams
tslib_fe::makeCacheHash

Blocking errors

  • If due to your coding TYPO3 stops working, just view the entries of the log file. (Linux: /var/log/messages or /var/log/httpd/error_log) and search for the string 'PHP Fatal error'.

HTML output into a file

To debug errors it would be usefull to let TYPO3 save the HTML output also into a file. Modify the printContent output function to save each page into the file typo3.log.

typo3/alt_main.php:

/**
* Outputting the accumulated content to screen and into a file
*
* @return	void
*/
function printContent()	{
 echo $this->content;
 $handle = fopen(t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT').'/typo3conf/','wb');
 fwrite ($handle, $this->content);
 fclose($handle);
}

Standards

Take care of standards to make all TYPO3 extensions look very similar. This helps that others can easier understand your extensions and find the files in it. Standardization. These are the current recommendations. And you are invited to make your own proposals. All things which are needed in several extensions should be defined by the same namings. So the setup for one extensions could be used 1:1 for another extension as well.

Send patches

Help

Personal tools