1

问题:如何在插件中启用来自组件router.php的路由?

我正在开发一个自定义插件,它从默认用户配置文件重定向路由:

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

到我自己的组件,我有其他设置

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

我的前端插件:

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

在我的组件中,所有链接都正确路由,即:

index.php?option=com_mycomponent&view=profile => /alias /profile

在插件 JRoute 中将其翻译如下:

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

不能用:

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

1 回答 1

2

在插件 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') );
于 2011-06-29T09:29:28.183 回答