使用“router.php”中的组件路由;在 Joomla 的自定义插件中

发布于 2024-11-17 22:20:07 字数 1478 浏览 7 评论 0原文

问题:如何在插件中启用来自组件 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 => /别名/个人资料

将其翻译如下:

index.php?option=com_mycomponent&view=profile => /组件/我的组件/配置文件

无法使用:

  • core hacks
  • .htaccess
  • Joomla Redirect Plugin

Question: How do I enable the Routes from my component's router.php in a plugin?

I'm working on a custom Plugin which redirects the route from default user profile:

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

to my own component where I've got additional settings

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

my front-end plugin:

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

In my component all links are routed correctly ie:

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

in the plugin JRoute translates it as follows:

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

can not use:

  • core hacks
  • .htaccess
  • Joomla Redirect Plugin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月如刀 2024-11-24 22:20:07

在插件 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') );

in the plugin xml file you should add new parameter that will allow you to choose the desired Itemid(menuitem)
so it should look like this

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

Then you will need to choose desired menuitem that has the alias that you wanted from the plugin parameters in the administrator area
then in the plugin itself just use like this:

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

and this is valid too

$route = JRoute::_('index.php?option=com_mycomponent&view=profile&Itemid='.$this->params->get('my_itemid') );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文