繁体   English   中英

Joomla获得插件ID

[英]Joomla get plugin id

我写了一个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;
}
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;
}

这就是诀窍。

在Joomla 3.x这是方式!

function pluginId($name,$type,$element,$folder)
{
    $db = JFactory::getDBO();
    $query = $db->getQuery(true);
    $query
        ->select($db->quoteName('a.extension_id'))
        ->from($db->quoteName('#__extensions', 'a'))
        ->where($db->quoteName('a.name').' = '.$db->quote($name))
        ->where($db->quoteName('a.type').' = '.$db->quote($type))
        ->where($db->quoteName('a.element').' = '.$db->quote($element))
        ->where($db->quoteName('a.folder').' = '.$db->quote($folder));
    $db->setQuery($query);
    $db->execute();
    if($db->getNumRows()){
        return $db->loadResult();
    }
    return false;
}

然后使用该功能:

$pluginId = pluginId('plg_system_getbibleactivitycron','plugin','getbibleactivitycron','system');

if($pluginId){
    echo 'Plugin id is: '. $pluginId;
} else {
    echo 'Plugin not installed';
}

也许这个代码对你有用,你可以在模态中使用它

$urla= JRequest::getVar('id'); // id article 
$urlb=JURI::current(); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM