My test PDF

Page 70

Inside TYPO3 - doc_core_inside

Backend Modules

For details on actual extension programming (which will also cover backend module programming), please refer to some of the extension programming tutorials around.

Initialize TYPO3 backend in a PHP shell script (CLI mode) Most scripts in TYPO3 expect to be executed from a web browser. However you might need to create a PHP script which is executed in a Unix shell as a cronjob. In itself PHP is capable of that as long as PHP was also compiled as a binary (typically “/usr/bin/php”) but you need to do some tricks in order to initialize TYPO3s backend environment.

Tricky script path The greatest challenge is to make the script recognize its own path. This is necessary for all includes afterwards. It seems that the path of the script is available as the variable $_ENV['_'] in most cases. However it changes value depending on how you call the script. In order to make life easy for our programming we decide that the script must always be executed by its absolute path. So “./myphpshellscript.phpsh” will not work, but “/abs/path/to/typo3conf/ext/myext/ myphpshellscript.phpsh” will.

Note about FreeBSD: It has been reported (by Rainer Kuhn, punkt.de – thanks) that on FreeBSD the path is not available in $_ENV['_'] but can be extracted from $_SERVER['argv'][0]. Generally there are not enough experience and knowledge about this issue to state something final, but for now we suggest a fall back solution as seen below where $_ENV['_'] is tested and if not found, falls back to $_SERVER['argv'][0]

Basic framework To set up a PHP shell script that initializes the TYPO3 you create a file with the framework here:

1: #! /usr/bin/php -q 2: <?php 3: 4: // ***************************************** 5: // Standard initialization of a CLI module: 6: // ***************************************** 7: 8: // Defining circumstances for CLI mode: 9: define('TYPO3_cliMode', TRUE); 10: 11: // Defining PATH_thisScript here: Must be the ABSOLUTE path of this script in the right context: 12: // This will work as long as the script is called by it's absolute path! 13: define("PATH_thisScript", $_ENV['_'] ? $_ENV['_'] : $_SERVER['_']); 14:

70


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.