[TYPO3-dev] [BE] makeInstance and call userfunc

Gijs Epping gijs.epping at efocus.nl
Tue Jan 29 19:03:21 CET 2008


Oliver Hader wrote:
> Hi,
> 
> Gijs Epping schrieb:
>> Francois Suter schreef:
>>> Hi,
>>>
>>>> Thanks, i replaced $this->IMAGE(); with 
>>>> $GLOBALS['TSFE']->cObj->IMAGE() and that is working but not for:
>>>>
>>>> $GLOBALS['TSFE']->cObj->pi_linkTP_keepPIvars_url
>>>
>>> No, this can't work. "cObj" is an instance of tslib_cObj, but 
>>> pi_linkTP_keepPIvars_url is a property of the tslib_pibase class. 
>>> There's no instance of tslib_pibase in the globals, because it is 
>>> instantianted specifically for each plugin.
>>>
>>> But if you create an instance of your plugin, e.g.
>>>
>>> $myplugin = t3lib_div::makeInstance('myplugin');
>>>
>>> then you can access the aforementioned variable as
>>>
>>> $myplugin->pi_linkTP_keepPIvars_url
>>>
>>> since your plugin class is supposed to extend tslib_pibase.
>>>
>>> HTH
>>>
>>
>>
>> he Francois,
>>
>> In pi3 i call pi1 with this: (thanks to you)
>>
>> $piConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_efrpho_pi1.'];
>> $obj = t3lib_div::makeInstance("tx_efrpho_pi1");
>> $content = $obj->main('',$piConf);
>>
>>
>> In pi1 i tryed using $this->pi_linkTP_keepPIvars_url(); But then i get 
>> the following error:
>>
>> Fatal error: Call to a member function typoLink() on a non-object in.
>>
>>
>> This is the inititation code of pi1:
>>
>> class tx_efrpho_pi1 extends tslib_pibase{
>>
>> }
>>
>> This should work as you say but it isn't.
>>
>> Any idea's?
> 
> The are two way how you can call a method of a different plugin from a 
> plugin.
> 
> 1) Using TypoScript:
> 
> plugin.tx_efrpho_pi3.renderObjPi1 = USER
> plugin.tx_efrpho_pi3.renderObjPi1.userFunc = tx_efrpho_pi1->main
> plugin.tx_efrpho_pi3.renderObjPi1.anyOtherKey = my_data_whatever
> 
> or e.g. simpler by just using
> 
> plugin.tx_efrpho_pi3.renderObjPi1 < plugin.tx_efrpho_pi1
> 
> and then in the PHP code of class tx_efrpho_pi3:
> 
> class tx_efrpho_pi3 extends tslib_pibase {
>   ...
>   function main($content, $conf) {
>      ...
>      $content.= $this->getpi1content($content, $conf);
>      ...
>   }
> 
>   function getpi1content($content, $conf) {
>     return $this->cObj->cObjGetSingle(
>       $conf['renderObjPi1'],
>       $conf['renderObjPi1.']
>     );
>   }
> }
> 
> 2) Using the PHP only approach:
> 
> class tx_efrpho_pi3 extends tslib_pibase {
>   ...
>   function main($content, $conf) {
>      ...
>      $content.= $this->getpi1content($content, $conf);
>      ...
>   }
> 
>   function getpi1content($content, $conf) {
>     $piConf = $GLOBALS['TSFE']->tmpl->...
>     $piObj = t3lib_div::makeInstance("tx_efrpho_pi1");
>     $piObj->cObj =& $this->cObj;
>     $piObj->theVerySpecialFunction($piConf, ...);
>   }
> }
> 
> 
> olly



Thank you very much olly this cObj addition did it......

So close and so far ;)

Thanks Again, both off you!

Regards Gijs




More information about the TYPO3-dev mailing list