[TYPO3-dev] Instantiating a cObject

Brian Slezak brian.slezak at cor.org
Sat Jun 24 05:16:21 CEST 2006


Bernhard, Ernesto,

You both make very good suggestions, and I am using this method where 
appropriate. In this case, I need to pass an array to the cObject, which I 
can not do with this method. I am implementing the class as a USER cObject 
though, to keep the configuration of it flexible. (My example did not 
explain this properly.)

My goal is to keep the PHP implementation simple, down to one statement.

Brian


"Bernhard Kraft" <kraftb at kraftb.at> wrote in message 
news:mailman.1.1151110031.31627.typo3-dev at lists.netfielders.de...
> 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