[TYPO3-dev] Fake / simulate frontend environment ( TSFE )
Mads Brunn
mads at brunn.dk
Wed Nov 21 08:15:44 CET 2007
Elmar,
I'm using the following to create a fake FE in the backend.
As can be seen from the example it can e.g. be used to generate
typolinks. Works pretty well.
./mads
if (!defined('PATH_tslib')) {
if (@is_dir(PATH_site.TYPO3_mainDir.'sysext/cms/tslib/')) {
define('PATH_tslib', PATH_site.TYPO3_mainDir.'sysext/cms/tslib/');
} elseif (@is_dir(PATH_site.'tslib/')) {
define('PATH_tslib', PATH_site.'tslib/');
}
}
require_once(PATH_t3lib.'class.t3lib_timetrack.php');
$GLOBALS['TT'] = new t3lib_timeTrack;
$GLOBALS['TT']->start();
$GLOBALS['TT']->push('','Script start');
require_once (PATH_tslib."class.tslib_fe.php");
require_once (PATH_tslib."class.tslib_content.php");
require_once (PATH_t3lib."class.t3lib_page.php");
require_once (PATH_t3lib."class.t3lib_userauth.php");
require_once (PATH_tslib."class.tslib_feuserauth.php");
require_once (PATH_t3lib."class.t3lib_tstemplate.php");
require_once(PATH_t3lib.'class.t3lib_cs.php');
$temp_TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
$GLOBALS['TSFE'] = new $temp_TSFEclassName(
$TYPO3_CONF_VARS,
7,
0,
0,
t3lib_div::_GP('cHash'),
t3lib_div::_GP('jumpurl'),
t3lib_div::_GP('MP'),
t3lib_div::_GP('RDCT')
);
$GLOBALS['TSFE']->connectToDB();
$GLOBALS['TSFE']->initFEuser();
$GLOBALS['TSFE']->determineId();
$GLOBALS['TSFE']->getCompressedTCarray();
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->getConfigArray();
$cObj = t3lib_div::makeInstance('tslib_cObj');
$content = $cObj->typolink('',
array(
'parameter' => 108,
'returnLast' => 'url',
) );
Elmar Hinz wrote:
> Hi,
>
> by request of Dmitry I start this topic as a new thread, to make it the more
> easy findable within the list.
>
> How to quickly fake a FE in the BE?
>
> Here is a very, very official solution from Robert, found in his extension
> t3unit, now followed by the extension phpunit:
>
> http://typo3.org/extensions/repository/view/phpunit/3.1.15/info/mod1%252Findex.php/
>
>
> /**
> * Roughly simulates the frontend although being in the backend.
> *
> * @return void
> * @todo This is a quick hack, needs proper implementation
> */
> protected function simulateFrontendEnviroment() {
>
> global $TSFE, $TYPO3_CONF_VARS;
>
> // FIXME: Currently bad workaround which only initializes a few
> things, not really what you'd call a frontend enviroment
>
> require_once(PATH_tslib.'class.tslib_fe.php');
> require_once(PATH_t3lib.'class.t3lib_page.php');
> require_once(PATH_t3lib.'class.t3lib_userauth.php');
> require_once(PATH_tslib.'class.tslib_feuserauth.php');
> require_once(PATH_t3lib.'class.t3lib_tstemplate.php');
> require_once(PATH_t3lib.'class.t3lib_cs.php');
>
> $temp_TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
> $TSFE = new $temp_TSFEclassName(
> $TYPO3_CONF_VARS,
> t3lib_div::_GP('id'),
> t3lib_div::_GP('type'),
> t3lib_div::_GP('no_cache'),
> t3lib_div::_GP('cHash'),
> t3lib_div::_GP('jumpurl'),
> t3lib_div::_GP('MP'),
> t3lib_div::_GP('RDCT')
> );
> $TSFE->connectToDB();
> $TSFE->config = array(); // Must be filled with actual
> config!
>
> }
>
>
More information about the TYPO3-dev
mailing list