从其他插件的主体调用 TYPO3 插件

发布于 2024-12-01 16:38:58 字数 232 浏览 6 评论 0原文

我需要从其他插件的主体调用typo3插件并将其结果传递给模板。这是伪代码,描述了我想要实现的目标:

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

这可能吗?

谢谢!

I need to call typo3 plugin from other plugin's body and 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我不吻晚风 2024-12-08 16:38:58

如果您使用整个 pi 构造(例如链接、标记函数等),它就不起作用,并且 TSFE 数据可能会损坏。

德米特里说:
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

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
携君以终年 2024-12-08 16:38:58

您应该使用 t3lib_div:makeInstance 方法。

TYPO3 的“powermail”扩展中有一个工作示例。

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
        }
    }

}

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
        }
    }

}
温柔少女心 2024-12-08 16:38:58

@mitchiru 的回答很好,基本上是正确的。

如果您已经使用 Kickstarter 创建了外部扩展并且正在使用 pi_base,那么已经存在 tslib_cObj 的实例,并且整个构造变得更简单:

// 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);

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);
傲性难收 2024-12-08 16:38:58

首先,您必须在使用之前或在类之外包含您的插件类:

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

其次在您的代码中(以 main 为例)

$res = tx_myext_pi1::myMethod();

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();
你与清晨阳光 2024-12-08 16:38:58

这肯定会起作用(我已经检查过了): http: //lists.typo3.org/pipermail/typo3-english/2008-August/052259.html

也许费迪尔的答案也是正确的,但我没有机会尝试。

干杯!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文