[TYPO3-dev] clarification about calling t3lib_cs methods

Jigal van Hemert jigal at xs4all.nl
Fri May 7 00:18:04 CEST 2010


Loek Hilgersom wrote:
> I'm working on a cli_backend module and tried to call
>     $filename = t3lib_cs::specCharsToASCII('utf-8',$filename);

None of the functions/methods in t3lib_cs is defined as static, so you 
can't call them this way.

> I could only get the first one to work if I first creat a new instance 
> of class t3lib_cs:
> 
>     $class = t3lib_div::makeInstanceClassName('t3lib_cs');
>     $t3libcs = new $class();
>     $filename = $t3libcs->specCharsToASCII($this->targetcharset, 
> $filename);

I think you can do it in an easier way.
If you expect your cli script to be called from cli_dispatch.phpsh the 
init.php is already called, so the $GLOBALS['LANG'] object is created.
This object has a property csConvObj which is an instance of t3lib_cs.

I would expect $GLOBALS['LANG']->csConvObj->specCharsToASCII() to work 
for your cli script.

To be completely safe:

if(!is_object($GLOBALS['LANG']) ) {
	require_once (PATH_typo3.'sysext/lang/lang.php');
	$GLOBALS['LANG'] = t3lib_div::makeInstance('language');
	$GLOBALS['LANG']->init('myDefaultLanguage');
}


-- 
Jigal van Hemert
skype:jigal.van.hemert
msn: jigal at xs4all.nl
http://twitter.com/jigalvh




More information about the TYPO3-dev mailing list