2

I can see all over the internet people are talking over this. While using JRoute::_($URL) we are forced to calculate the Itemid first and then append it to the input URL like:

JRoute::_('index.php?option=com_abc&view=xyz&id=32'.'&Itemid='.$itemid);

However, it is always desirable to calculate the Itemid automatically from within the Joomla core router from the given URL.

Since Joomla 1.5 through 3.2 today, the

JRouterSite::_buildSefRoute or the latest JRouterSite::buildSefRoute

has not changed significantly.

I can see in the codes at /libraries/cms/router/site.php file that to build the desired format sef URL it is mandatory to include Itemid=XXX in the passed URL. Otherwise

JRoute::_('index.php?option=com_abc&view=xyz&id=32');

will generate a URL something similar to

`/component/abc/?view=xyz&id=32` 

unlike the desired

/our-component/?id=32

where our-component is the menu alias for the menu item pointing to

index.php?option=com_abc&view=xyz

I know that the later half ?view=xyz&id=32 can be handled by using custom router.php file per component. But the component base URL /component/abc is out of scope for that custom router.php

Please somebody advise that am I right at this thought or I am missing something big. Also advise me for how to overcome this issue.

Izhar Aazmi
  • 915
  • 12
  • 25
  • 1
    There is no reason why you can't have your custom router.php file also look through the different menu items and determine the best Itemid to use for routing that link. I have done this in many custom components. `JFactory::getApplication()->getMenu()` returns the full menu tree. – David Fritsch Mar 11 '14 at 16:33
  • Of course I can (**and I do**) have my custom router.php file there. But the component identifier which lets Joomla know which component to call for route is set by Joomla itself and beyond the scope of my router.php. I am concerned for `/component/abc` part. Additionally my component has many pages each with different menu item linked, hence different `Itemid` – Izhar Aazmi Mar 11 '14 at 20:16

1 Answers1

1

The /component/abc is generated by the Joomla routing. Your component router.php will take care of the parameters which the component handles, so your /our-component/?id=32 may be translated into /our-component/my-id32-alias. It's not desirable that any component can tweek the basic routing on which all other components are based, and that's why you only can make-up part of the URL using router.php

Maybe you can investigate how to augment the router using a system plugin, but I think it is not what you are looking for.

http://docs.joomla.org/J2.5:Creating_a_System_Plugin_to_augment_JRouter

I've read it many times, but I find it hard to understand.

Pep Lainez
  • 949
  • 7
  • 12
  • 2
    The only thing that suits better is JRouter should first try to automatically detect appropriate menu alias or `Itemid` and only if not found then use the `/component/abc` format. Why do we have to write same code again and again to calculate `Itemid` in spite of having the framework! – Izhar Aazmi Mar 12 '14 at 13:56