我正在开发一个应该为插件提供支持的插件。但是我没有让它调用(并执行)它自己的插件——我已经前后阅读了文档,而且我一生都没有看到问题。
所以我建立了一个简单的例子来理解机制 - 幸运的是这个例子也失败了,所以至少我的(错误)理解是一致的......
主插件是这个(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 类型的 mainplugin_plugin 插件,它被称为 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>