gpt4 book ai didi

php - Joomla 获取插件 ID

转载 作者:可可西里 更新时间:2023-11-01 13:57:39 26 4
gpt4 key购买 nike

我写了一个 Joomla 插件,它最终会加载一个库。

库的路径是一个插件参数,所以当路径不正确时,后台会弹出一条消息,并附上编辑插件参数的链接:

/administrator/index.php?option=com_plugins&view=plugin&client=site&task=edit&cid[]=36

看到最后的 36 了吗?这是我的插件在数据库中的 ID(表 jos_plugins)。

我的问题是这个 id 在安装时会发生变化,也就是说,在不同的安装中,它会是别的东西。所以我需要以编程方式找到这个 ID。

问题是我无法从插件对象本身找到这个 id(至于为什么不能,那可以说是 joomla 短视的设计决定)。

所以除非你知道一些巧妙的技巧,(我已经检查并仔细检查了 JPlugin 和 JPluginHelper 类),否则我将使用数据库。

编辑;一些有用的链接:

我想我会利用最后一个链接中的智慧...

最佳答案

对于 joomla 2.5.x 和 3.x Christian 的功能改进是;

function getId($folder,$name){
$db= JFactory::getDBO();
$sql='SELECT extension_id FROM #__extensions WHERE folder ="'.$db->getEscaped($folder).'" AND element ="'.$db->getEscaped($name).'"';
$db->setQuery($sql);
if(!($plg=$db->loadObject())){
JError::raiseError(100,'Fatal: Plugin is not installed or your SQL server is NUTS.');
}else return (int)$plg->extension_id;
}

关于php - Joomla 获取插件 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4358254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com