[TYPO3-english] cObj (IMAGE) in backend module
"Christian Müller (Kitsunet)"
christian at kitsunet.de
Wed Jan 5 19:07:13 CET 2011
Hi Søren,
Happy New Year!
cObj relies heavily on TSFE, so you need a full TSFE in backend to get a
cObj. Alternative would be to look at tslib_gifbuilder directly.
a fire and forget function to get TSFE in backend that I have stored
away is this, put it into your BE class or as I do in into a "lib_div"
as static function:
function buildTSFE($pid = 1) {
//needed for TSFE
require_once(PATH_t3lib.'class.t3lib_timetrack.php');
require_once(PATH_t3lib.'class.t3lib_tsparser_ext.php');
require_once(PATH_t3lib.'class.t3lib_page.php');
require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
require_once($BACK_PATH.'sysext/cms/tslib/class.tslib_fe.php');
require_once($BACK_PATH.'sysext/cms/tslib/class.tslib_content.php');
require_once($BACK_PATH.'sysext/cms/tslib/class.tslib_gifbuilder.php');
/* Declare */
$temp_TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
/* Begin */
if (!is_object($GLOBALS['TT'])) {
$GLOBALS['TT'] = new t3lib_timeTrack;
$GLOBALS['TT']->start();
}
if (!is_object($GLOBALS['TSFE']) && $pid) {
//*** Builds TSFE object
$GLOBALS['TSFE'] = new
$temp_TSFEclassName($GLOBALS['TYPO3_CONF_VARS'],$pid,0,0,0,0,0,0);
//*** Builds sub objects
$GLOBALS['TSFE']->tmpl = t3lib_div::makeInstance('t3lib_tsparser_ext');
$GLOBALS['TSFE']->sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
//*** init template
$GLOBALS['TSFE']->tmpl->tt_track = 0;// Do not log time-performance
information
$GLOBALS['TSFE']->tmpl->init();
$rootLine = $GLOBALS['TSFE']->sys_page->getRootLine($pid);
//*** This generates the constants/config + hierarchy info for the
template.
$GLOBALS['TSFE']->tmpl->runThroughTemplates($rootLine,$template_uid);
$GLOBALS['TSFE']->tmpl->generateConfig();
$GLOBALS['TSFE']->tmpl->loaded=1;
//*** Get config array and other init from pagegen
$GLOBALS['TSFE']->getConfigArray();
$GLOBALS['TSFE']->linkVars =
''.$GLOBALS['TSFE']->config['config']['linkVars'];
if
($GLOBALS['TSFE']->config['config']['simulateStaticDocuments_pEnc_onlyP'])
{
foreach
(t3lib_div::trimExplode(',',$GLOBALS['TSFE']->config['config']['simulateStaticDocuments_pEnc_onlyP'],1)
as $temp_p)
{
$GLOBALS['TSFE']->pEncAllowedParamNames[$temp_p]=1;
}
}
//*** Builds a cObj
$GLOBALS['TSFE']->newCObj();
}
}
Christian
On 05.01.2011 18:30, Søren Malling wrote:
> Hi,
>
> Happy new year! :)
>
> The short question: Is it possible to use a cObj in a backend module?
>
> My real issue: A client have created some database records, where one
> of the fields are a relation to a file/image. This image can be
> uploaded in any resolution. I would like to use the function IMAGE
> from tslib_cObj to create some nice thumbnails of the uploaded
> images.
>
> In my backend module the cObj is initialized like this
>
> function init() {
> $this->cObj = t3lib_div::makeInstance('tslib_cObj');
> }
>
> and used in my main() function like this
>
> $this->content .= $this->cObj->IMAGE(array(
> 'file' => $templateObject['previewicon'],
> 'file.' => array(
> 'maxW' => 200,
> 'maxH' => 200
> )
> ));
>
> and the error I get is
>
> Fatal error: Call to a member function getFileName() on a non-object
> in /opt/local/apache2/htdocs/site/typo3/sysext/cms/tslib/class.tslib_content.php
> on line 4916
>
> Can someone shed some light on this issue?
>
> Best regards,
>
> Søren Malling
>
> TYPO3 Brugergruppe Danmark: www.typo3danmark.dk
> Twitter: twitter.com/sorenmalling
More information about the TYPO3-english
mailing list