Login / Status
developer.Resource
Home . Documentation . Document Library . Extension Manuals
Sponsors
hosted by punkt.deTYPO3 and Open Source MagazineAOE Media

1.4. Automatic configuration

Overview

Since version 1.4 RealURL has automatic configuration option. It checks the system and attempts to write configuration file to simplify work for user. Such check if done is user did not specify configuration manually. While RealURL tries to make optimal configuration, it does it for most common cases. If your host needs specific settings, you should either write configuration manually or modify generated configuration.

RealURL will create configuration for each domain and for each language defined in the system. To create language configuration it requires static_tables extension. static_tables is suggested during installation of RealURL. If you do not plan to use automatic configuration or you have only one language, you can skip static_tables.

RealURL may store generated configuration in one of two formats: PHP serialized array or source PHP code. These options are offered during extension installation. The first option is at least 10 times faster (may be less with PHP accelerator) and it should be used in production environment. However serialized arrays cannot (and must not be under any conditions!) modified manually. Serialized array may stop working after you upgrade PHP version, though this happens really rare. In any case, use the second option only if:

  1. you plan to modify generated configuration

  2. you plan to update to newer PHP version really soon

Important: configuration is generated only once. If you add domain or new language to the system, automatic configuration will not be updated. You have to delete a file in typo3conf/ directory named realurl_autoconf.php. RealURl will regenerate configuration if this file does not exist.

If you use manual configuration, you can disable autogeneration by clearing a checkbox while installing extension. This will save you a couple of milliseconds.

Automatic configuration of extensions

Extensions can alter generated RealURL configuration to suit there needs. Notice that it is done only once when configuration is generated. If you install and extension that supports autogeneration, you need to delete a file in typo3conf/ directory named realurl_autoconf.php. RealURl will regenerate configuration if this file does not exist.

To add/modify RealURL configuration, extensions  must provide a hook to RealURL. This hook will be called once and receive RealURL configuration as array. This array is a template, not a final configuration. RealURL will use this array to generate separate set of arrays for each domain. Think about this array as about _DEFAULT entry in RealURL confuiguration.

The following code example from album3x extension shows how to set such hook in locaconf.php:

// RealURL autoconfiguration
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/realurl/class.tx_realurl_autoconfgen.php']['extensionConfiguration']['album3x'] = 'EXT:album3x/class.tx_album3x_realurl.php:tx_album3x_realurl->addAlbum3xConfig'

Here is an example of the hook from album3x extension:

class tx_album3x_realurl {

/**
 * Generates additional RealURL configuration and merges it with provided configuration
 *
 * @paramarray$paramsDefault configuration
 * @paramtx_realurl_autoconfgen$pObjParent object
 * @returnarrayUpdated configuration
 */
function addAlbum3xConfig($params, &$pObj) {
return array_merge_recursive($params['config'], array(
    'postVarSets' => array(
'_DEFAULT' => array(
'page3x' => array(
array(
'GETvar' => 'tx_album3x_pi1[page]',
),
),
'image3x' => array(
array(
'GETvar' => 'tx_album3x_pi1[showUid]',
'userFunc' => 'EXT:album3x/class.tx_album3x_realurl.php:&tx_album3x_realurl->main',
),
),
))));
}
}

Important note: try to invent preVar, postVar and fixedPostVar names that do not conflict with other extensions. Since variable names should look good in the URL, choice is limited and conflicts may occure. For example, mininews extension try to prevent conflict with tt_news by changing postVar name if tt_news is installed:

class tx_mininews_realurl {
/**
 * Generates additional RealURL configuration and merges it with provided configuration
 *
 * @paramarray$paramsDefault configuration
 * @paramtx_realurl_autoconfgen$pObjParent object
 */
function addMininewsConfig($params, &$pObj) {
$postVar = (t3lib_extMgm::isLoaded('tt_news') ? 'mnews' : 'news');
return array_merge_recursive($params['config'], array(
'postVarSets' => array(
'_DEFAULT' => array(
$postVar => array(
    'GETvar' => 'tx_mininews_pi1[showUid]'
)
)
)
));
}
}