为什么我的插件未触发? [英] Why is my plugin not triggered?

查看:96
本文介绍了为什么我的插件未触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working on a plugin which should provide support for plugins. But I don't get it to call (and execute) its own plugins - and I have read the doc forward and backward and for the life of me am not seeing the problem.

因此,我构建了一个简单的示例来理解该机制-幸运的是,该示例也失败了,因此至少我的(误解)理解是一致的...

So I build a simple example to understand the mechanism - and fortunately the example fails as well, so at least my (mis)-understanding is consistent...

主要插件是这个(mainplugin.php).

The main-plugin is this (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一起安装:

And it is installed with 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:

Here is a plugin for mainplugin of type mainplugin_plugin and it is called 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):

and its installer (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>

推荐答案

在您的xml中,您说的是

In your xml you say the group is

group="mainplugin_plugin"

    JPluginHelper::importPlugin('mainplugin_plugin');

但是随后您将其视为内容组的一部分.

but then you are treating it like part of the content group later.

class plgContentMainplugin_plugin extends  plgContentMainplugin

您需要对此下定决心,并确保插件在正确的文件夹中,并且您使用正确的组名进行呼叫.

You need to make up your mind on this and make sure the plugin is in the right folder and you are calling by the right groupt name.

请注意,importPlugin将组名作为第一个参数,将特定的插件名作为第二个可选参数.

Note that importPlugin takes the group name as the first argument and the specific plugin name as the second optional one.

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

I also don't know why you would be extending a plugin class normally. I mean you could ... but I don't think if you do that you should be extending it in a different group.

这篇关于为什么我的插件未触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆