Chr*_*ian 5 php joomla plugins
我写了一个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;
}
Run Code Online (Sandbox Code Playgroud)
function getId($folder,$name){
$db=&JFactory::getDBO();
$sql='SELECT `id` FROM `#__plugins` 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->id;
}
Run Code Online (Sandbox Code Playgroud)
这就成功了。
| 归档时间: |
|
| 查看次数: |
1494 次 |
| 最近记录: |