2012-05-17 4 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

줌라는 설치시이 메뉴 항목을 자동으로 삽입하지만 실제로 원한다면 다양한 방법으로 제거 할 수 있습니다.

가장 간단한 방법은 구성 요소의 행에 대한 메뉴 테이블의 client_id 필드를 변경하는 것입니다. 관리자 메뉴 항목에 client_id = 1이 있지만이 내용을 client_id = 10과 같이 무의미한 것으로 변경하면 관리 사이트에 표시되지 않습니다.

또는 완전히 삭제할 수 있습니다. 메뉴 테이블은 중첩 세트 모델을 사용하기 때문에 행을 삭제하면 안됩니다. 아마도 최선의 최선의 방법은 MenusModelMenu 클래스의 삭제 기능을 사용하는 것입니다.

설치 프로그램에 postflight 기능이있는 스크립트가있는 경우 구성 요소 설치 중에 이러한 작업을 수행 할 수 있습니다.

1

이것은 관리자 메뉴에서 항목을 제거하는 데 사용 된 코드입니다. 구성 요소를 설치 한 후

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

} 

다음 내가 스크립트를 실행하는 데, 구성 요소 매니페스트에 항목을 추가 :

먼저 내가이 script.php라는 파일에 포스트 비행 방법을 구현하는 설치 스크립트를 생성 :

<scriptfile>script.php</scriptfile>