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 也很有趣。

4

2 回答 2

3

Joomla 会在安装时自动插入这些菜单项,但如果你真的想的话,你可以通过各种方式去掉它们。

最简单的方法是client_id在菜单表中更改组件行的字段。管理菜单项有client_id = 1,但如果您将其更改为诸如 之类的废话client_id = 10,它们将不会显示在管理站点中。

或者,您可以直接删除它们。因为菜单表使用嵌套集模型,所以不应该只删除行。可能你最好的方法是使用MenusModelMenu类的删除功能。

如果您的安装程序包含具有postflight函数的脚本,则可以在组件安装期间完成上述任何一项操作。

于 2012-05-18T01:32:43.967 回答
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>
于 2012-05-20T07:55:28.033 回答