2012-05-17 41 views
1

有誰知道如何創建一個不在管理菜單中創建節的Joomla組件?沒有管理菜單的組件

我已經刪除了所有的菜單項的清單,但它仍然會創建一個管理員菜單項:

<administration> 
      <files folder="admin"> 
        <filename>index.html</filename> 
        <filename>gallery.php</filename> 
        <filename>controller.php</filename> 
        <folder>views</folder> 
        <folder>models</folder> 
      </files> 
</administration> 

任何想法?

注意:這是關於J2.5,但1.5也很有趣。

+0

如果我沒有弄錯,Joomla核心代碼會自動發生這種情況。我不認爲你想要什麼是可能的。你爲什麼要從管理組件列表中刪除它? – Lodder

+0

該組件僅用作需要代理類的模塊的組件助手。使用組件是我知道實現這一目標的唯一途徑。 – Stilero

回答

3

Joomla會在安裝時自動插入這些菜單項,但如果您真的想要的話,您可以通過各種方式擺脫它們。

最簡單的方法是更改​​組件行的菜單表的client_id字段。管理菜單項有client_id = 1,但如果您將其更改爲client_id = 10等一些無意義內容,則它們將不會顯示在管理站點中。

或者,您可以徹底刪除它們。由於菜單表使用嵌套集模型,因此不應該只刪除該行。可能你最好的選擇是使用MenusModelMenu類的刪除功能。

如果安裝程序包含具有postflight函數的腳本,則可以在組件安裝期間完成以上任何一項操作。

1

這是我最終用於刪除管理菜單中的條目的代碼。

首先,我創建了一個實現在一個文件中的飛行後的方法稱爲script.php的安裝腳本:

<?php 
//No direct access 
defined('_JEXEC) or die;'); 

class com_mycomponentInstallerScript{ 
    function postflight($type, $parent){ 
     // $parent is the class calling this method 
    // $type is the type of change (install, update or discover_install) 
     $componentName = 'myComponent'; //The name you're using in the manifest 
     $extIds = $this->getExtensionIds($componentName); 
     if(count($extIds)) { 
      foreach($extIds as $id) { 
       if(!$this->removeAdminMenus($id)) { 
        echo JText::_(COM_MYCOMPONENT_POSTFLIGHT_FAILED); 
       } 
      } 
     } 
    } 

    /** 
    * Retrieves the #__extensions IDs of a component given the component name (eg "com_somecomponent") 
    * 
    * @param string $component The component's name 
    * @return array An array of component IDs 
    */ 
    protected function getExtensionIds($component) { 
     $db = JFactory::getDbo(); 
     $query = $db->getQuery(true); 
     $query->select('extension_id'); 
     $query->from('#__extensions'); 
     $cleanComponent = filter_var($component, FILTER_SANITIZE_MAGIC_QUOTES); 
     $query->where($query->qn('name') . ' = ' . $query->quote($cleanComponent)); 
     $db->setQuery($query); 
     $ids = $db->loadResultArray(); 
     return $ids; 
    } 

    /** 
    * Removes the admin menu item for a given component 
    * 
    * This method was pilfered from JInstallerComponent::_removeAdminMenus() 
    * 
    * @param int  $id The component's #__extensions id 
    * @return bool true on success, false on failure 
    */ 
    protected function removeAdminMenus(&$id) 
    { 
     // Initialise Variables 
     $db = JFactory::getDbo(); 
     $table = JTable::getInstance('menu'); 
     // Get the ids of the menu items 
     $query = $db->getQuery(true); 
     $query->select('id'); 
     $query->from('#__menu'); 
     $query->where($query->qn('client_id') . ' = 1'); 
     $query->where($query->qn('component_id') . ' = ' . (int) $id); 

     $db->setQuery($query); 

     $ids = $db->loadColumn(); 

     // Check for error 
     if ($error = $db->getErrorMsg()) 
     { 
     return false; 
     } 
     elseif (!empty($ids)) 
     { 
     // Iterate the items to delete each one. 
     foreach ($ids as $menuid) 
     { 
      if (!$table->delete((int) $menuid)) 
      { 
       return false; 
      } 
     } 
     // Rebuild the whole tree 
     $table->rebuild(); 
     } 
     return true; 
    } 

} 

接下來,我加入與組件清單中的條目,運行腳本安裝的組件後, :

<scriptfile>script.php</scriptfile>