[TYPO3-dev] Instantiating a cObject

Bernhard Kraft kraftb at kraftb.at
Sat Jun 24 02:47:11 CEST 2006


Brian Slezak wrote:


> $my_class = t3lib_div::makeInstance('my_cObject );
> $content =
> $this->cObj->cObjGetSingle($GLOBALS['TSFE']->tmpl->setup['plugin.']['my_cObject'],
> $GLOBALS['TSFE']->tmpl->setup['plugin.']['my_cObject.']);
> 
> Stating the question again, is it ok to go at the TypoScript configuration
> via $GLOBALS['TSFE']->tmpl->setup['plugin.']['my_cObject'] like that, or is
> there a better way to accomplish this?


I would consider Ernestos notice as very important...

you should rather set:

plugin.tx_myext_pi1.my_cObject = WHATEVER
plugin.tx_myext_pi1.my_cObject	{
	...
}

And then use lines like:

$myClass = $this->cObj;	// Create copy of local cObject
$myClass->start($whateverRowOrArray);	// Fill the cObj ->data array
$content = $myClass->cObjGetSingle($this->conf['my_cObject'], $this->conf['my_cObject.']);	// Render the cObject


Especially note the 2nd line where the ->data array get's filled. You should pass "the row"
for which you are rendering the cObject (or $this->data of the pi1 FE plugin - but normally
the cObj is already instantiated with the data from there) to the ->start method.

With this usage the cObject get's a MUCH broader usefullness ... as you can access every field
in the actual row (which you passed) using the .field operator in stdWrap for example.

Example:


plugin.tx_myext_pi1.my_cObject = TEXT
plugin.tx_myext_pi1.my_cObject.field = keyInArrayPassedTo_start

which will render the value of the specified field.




greets,
Bernhard
-- 
----------------------------------------------------------------------
"Freiheit ist immer auch die Freiheit des Andersdenkenden"
Rosa Luxemburg, 1871 - 1919
----------------------------------------------------------------------
[[ http://think-open.at | Open source company ]]




More information about the TYPO3-dev mailing list