1

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
tereško
  • 58,060
  • 25
  • 98
  • 150
WooDzu
  • 4,771
  • 6
  • 31
  • 61

1 Answers1

2

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') );
Azamat Tokhtaev
  • 447
  • 3
  • 8
  • thanks very much for your post, even though I've already found a soultion. I'm sure this would work but not where more than one language is used on site. To solve it I used a link as the param and current language to get **Itemid** from 'jos_menu' table – WooDzu Jun 29 '11 at 14:01