开发者

Call TYPO3 plugin from other plugin's body

开发者 https://www.devze.com 2023-03-31 04:07 出处:网络
I need to call typo3 plugin from other plugin\'s body an开发者_StackOverflow社区d pass its result to template. This is pseudo-code that describes what I want to achieve doing this:

I need to call typo3 plugin from other plugin's body an开发者_StackOverflow社区d pass its result to template. This is pseudo-code that describes what I want to achieve doing this:

$data['###SOME_VARIABLE###'] = $someOtherPlugin->main();
$this->cObj->substituteMarkerArray($someTemplate, $data);

Is it possible?

Thanks!


It doenst work if you use the whole pi construct, e.g. for links, marker function etc, and the TSFE Data can be corrupted.

Dmitry said: http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html

$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1'];
$conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1.'];
$cObj = t3lib_div::makeInstance('tslib_cObj');
$cObj->start(array(), '_NO_TABLE');
$conf['val'] = 1;
$content = $cObj->cObjGetSingle($cObjType, $conf); //calling the main method


You should use t3lib_div:makeInstance method.

There is a working example from TYPO3's "powermail" extension.

function getGeo() {
    // use geo ip if loaded
    if (t3lib_extMgm::isLoaded('geoip')) {
        require_once( t3lib_extMgm::extPath('geoip').'/pi1/class.tx_geoip_pi1.php');
        $this->media = t3lib_div::makeInstance('tx_geoip_pi1');
        if ($this->conf['geoip.']['file']) { // only if file for geoip is set
            $this->media->init($this->conf['geoip.']['file']); // Initialize the geoip Ext
            $this->GEOinfos = $this->media->getGeoIP($this->ipOverride ? $this->ipOverride : t3lib_div::getIndpEnv('REMOTE_ADDR')); // get all the infos of current user ip
        }
    }

}


The answer of @mitchiru is nice and basically correct.

If you have created your outer extension with Kickstarter and you are using pi_base then there is already an instance of tslib_cObj and the whole construct becomes simpler:

// get type of inner extension, eg. USER or USER_INT
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1'];
// get configuration array of inner extension
$cObjConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1.'];
// add own parameters to configuration array if needed - otherwise skip this line
$cObjConf['myparam'] = 'myvalue';
// call main method of inner extension, using cObj of outer extension
$content = $this->cObj->cObjGetSingle($cObjType, $cObjConf);


Firstly, you have to include your plugin class, before using, or outside your class:

include_once(t3lib_extMgm::extPath('myext').'pi1/class.tx_myext_pi1.php');

Secondly in your code (in the main as example)

$res = tx_myext_pi1::myMethod();


This will work for sure (I've checked this): http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html.

Probably Fedir's answer is correct too but I didn't have a chance to try it.

Cheers!

0

精彩评论

暂无评论...
验证码 换一张
取 消