2011-06-27 27 views
1

問題:如何在插件中啓用組件的router.php中的路由?從Joomla的自定義插件中的'router.php'使用組件路由

我正在從默認用戶配置文件重定向路徑的自定義插件:

index.php?option=com_users&view=profile (SEF: /component/users/profile) 

我自己的分量,我已經得到了額外的設置

index.php?option=com_mycomponent&view=profile (SEF: /alias/profile) 

我的前置式end插件:

class plgSystemMyPlugin extends JPlugin 
{ 
    // constructor 
    function plgSystemMyPlugin(&$subject, $params) { 
     parent::__construct($subject, $params); 
    } 

    // run after the framework has loaded and the application initialize method has been called 
    function onAfterInitialise() { 

     // when component users and view profile are called 
     if(isset($_GET['option'], $_GET['view']) 
      && $_GET['option'] == 'com_users' 
      && $_GET['view'] == 'profile') 
     { 
       $route = JRoute::_('index.php?option=com_mycomponent&view=profile'); 
       JFactory::getApplication()->redirect($route, null, null, true); 
     } 
    } 
} 

在我的組件中,所有的鏈接都被路由到correctl ÿ即:

的index.php選項= com_mycomponent &視圖=輪廓=>/別名 /簡檔

在插件JROUTE其翻譯如下

索引.php?option = com_mycomponent & view = profile =>/component/mycomponent/profile

不能使用:

  • 核心的黑客
  • 的.htaccess
  • 的Joomla重定向插件

回答

1

你應該添加新的參數,讓您選擇插件xml文件所需的Itemid(menuitem) 所以它應該看起來像這樣

<param name="menuitem" name="my_itemid" title="Target Itemid" description=""/> 

然後你需要選擇有你在那麼管理員區域 插件參數插件本身只是用這樣想的別名所需的菜單項:

$route = JRoute::_('index.php?Itemid='.$this->params->get('my_itemid')); 

,這是有效的太

$route = JRoute::_('index.php?option=com_mycomponent&view=profile&Itemid='.$this->params->get('my_itemid')); 
+0

非常感謝您的文章,儘管我已經找到了靈魂。我確信這會起作用,但不是在現場使用多種語言的地方。爲了解決這個問題,我使用了一個鏈接作爲param和當前語言,從'jos_menu'表中獲取** Itemid ** – WooDzu