2010-12-05 77 views
4

我寫了一個Joomla插件,最終將加載一個庫。Joomla獲取插件ID

到庫中的路徑是一個插件參數,因爲諸如當路徑不正確,消息在後端彈出,與鏈接在一起以編輯插件參數:

/管理員/索引。 PHP?選項= com_plugins &視圖=插件&客戶=站點&任務=編輯& CID [] = 36

參見末尾的36?這是我的數據庫中的插件ID(表jos_plugins)。

我的問題是,這個id在安裝時發生變化,即在不同的安裝時,它會是別的。 所以我需要通過編程方式找到這個ID。

問題是,我無法從插件對象本身找到此ID(至於爲什麼不,這將是joomla的可以說是短視的設計決定)。

所以,除非你知道一些巧妙的技巧,(我已經檢查並重複檢查JPlugin和JPluginHelper類),否則我將使用數據庫。

編輯;一些有用的鏈接:我會用智慧,從最後一個環節

猜...

回答

2
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; 
} 

這個技巧。

0

也許這代碼對您有用,您可以在模式

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

你忽略了一點,我需要去**插件ID **,**不是文章編號**。 – Christian 2012-11-12 01:04:38

3

使用此爲Joomla 2.5.X和3.x基督徒的功能改進是;

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