【问题标题】:Joomla get plugin idJoomla 获取插件 ID
【发布时间】:2011-05-20 11:38:23
【问题描述】:

我写了一个 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 类),否则我将使用 DB。

编辑;一些有用的链接:

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

【问题讨论】:

    标签: php plugins joomla


    【解决方案1】:

    在 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';
    }
    

    【讨论】:

      【解决方案2】:

      对于 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;
      }
      

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

        • 你没有抓住重点,我需要的是 plugin id,而不是 article id
        【解决方案4】:
        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;
        }
        

        成功了。

        【讨论】:

          猜你喜欢
          • 2011-08-28
          • 1970-01-01
          • 1970-01-01
          • 2017-09-24
          • 1970-01-01
          • 2013-08-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多