为什么我的插件没有被触发?

时间:2013-08-08 19:07:36

标签: joomla joomla2.5

我正在开发一个应该为插件提供支持的插件。但是我不能让它调用(并执行)它自己的插件 - 而且我已经向前和向后阅读了文档,而且我的生活中没有看到问题。

所以我构建了一个简单的例子来理解这个机制 - 幸运的是,这个例子也失败了,所以至少我的(误)理解是一致的......

main-plugin就是这个(mainplugin.php)。

<?php

jimport('joomla.plugin.plugin');

class plgContentMainplugin extends JPlugin
{
    function onAfterRender()
    {                           
        JPluginHelper::importPlugin('mainplugin_plugin');
        $dispatcher = JDispatcher::getInstance();
        $a="collecting calls\n";
        $data = array("Hello", &$a);
        $res = $dispatcher->trigger('onmainiscalling', $data);
        $tmp="res of trigger: " . nl2br(print_r($res,true));
        echo '<div style="border: 3px black solid; background-color: yellow; color: black;">';
        echo '<h1>Here is the result of "onmainiscalling"</h1>' . $tmp;
        echo '</div>';
    }

    function onmainiscalling($data) {
        $r="own fn was called";
        return $r;
    }
}

?>

它与mainplugin.xml一起安装:

<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="1.6" method="upgrade" group="content">
    <name>Content - mainplugin</name>
    <creationDate>2013-08-07</creationDate>
    <version>1</version>
    <releaseDate>2013-08-07 22:00:21</releaseDate>
    <releaseType>First public release!</releaseType>
    <author>Michael Baas</author>
    <authorEmail>mb@mbaas.de</authorEmail>
    <authorUrl>mbaas.de</authorUrl>
    <copyright>(c) 2005-2013 Michael Baas</copyright>
    <description>Testing the plugins-for-plugins-concept</description>
    <license>free free free</license>
    <files>
        <filename plugin="mainplugin">mainplugin.php</filename>
    </files>
    <config />
</extension>

这是mainplugin_plugin类型的mainplugin插件,它名为mainplugin_plugin.php:

<?php

class plgContentMainplugin_plugin extends  plgContentMainplugin // or should it be JPlugin? Tried both, nothing worked.
{

    function onmainiscalling($data) {
        $r="Mainplugin_plugin->onmainiscalling was called";
        return $r;
    }

}

?>

及其安装程序(mainplugin_plugin.xml):

<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="1.6" method="upgrade" group="mainplugin_plugin">
    <name>Content - mainplugin_plugin</name>
    <creationDate>2013-08-07</creationDate>
    <version>1</version>
    <releaseDate>2013-08-07 22:00:21</releaseDate>
    <releaseType>First public release!</releaseType>
    <author>Michael Baas</author>
    <authorEmail>mb@mbaas.de</authorEmail>
    <authorUrl>mbaas.de</authorUrl>
    <copyright>(c) 2005-2013 Michael Baas</copyright>
    <description>Testing the plugins-for-plugins-concept</description>
    <license>free free free</license>
    <files>
        <filename plugin="mainplugin_plugin">mainplugin_plugin.php</filename>
    </files>
    <config />
</extension>

1 个答案:

答案 0 :(得分:2)

在您的xml中,您说该组是

group="mainplugin_plugin"

    JPluginHelper::importPlugin('mainplugin_plugin');

但是之后您将其视为内容组的一部分。

class plgContentMainplugin_plugin extends  plgContentMainplugin

您需要对此做出决定,并确保插件位于正确的文件夹中,并且您正在通过正确的组织名称进行调用。

请注意,importPlugin将组名作为第一个参数,将特定插件名称作为第二个参数。

我也不知道你为什么要正常扩展一个插件类。我的意思是你可以......但我不认为如果你这样做,你应该把它扩展到另一组。