我在joomla中创建了一个系统插件,并创建了一种自定义方法mymethod()
。现在我想通过ajax调用这个方法。我尝试过链接,但它会创建新的ajax插件,但我想调用系统插件自定义方法,而不是创建新的插件。
您可以使用插件系统事件onAfterInitialise()
。
将此url用于ajax:index.php?type=mymethod
这导致:
function onAfterInitialise() {
$jinput = JFactory::getApplication()->input;
if($jinput->get('type')=='mymethod') {
// your code here
}
}
链接是可以的。您只需要将文件夹名称从ajax更改为system。在joomla3.4之前,必须将插件放在ajax文件夹中,但现在可以放在任何文件夹中。你的代码看起来像这个
JPluginHelper::importPlugin('system');
$plugin = ucfirst($input->get('plugin'));
$dispatcher = JEventDispatcher::getInstance();
try
{
$results = $dispatcher->trigger('myMethod' . $plugin);
}
catch (Exception $e)
{
$results = $e;
}
按照那里给出的休息指示进行。