Joomla! Routing Explained
Anatomy of a non-sef URLindex.php?option=com_content&view=category&layout=blog&id=8&Itemid=103
Itemid is king !- Notice how you write Itemid (Capital I)
- It’s the id (primary key) of the menu created
- Modules are assigned to a menu, will show up when a link having the respective Itemid shows up
- This means if you change the Itemid for any other link, a different set of modules will load. This is not desirable
- If you leave out the Itemid, only modules set to show on ‘All’ pages will show
SEF URLs Explained/index.php?option=com_content&view=category&layout=blog&id=8&Itemid=103
Changes to /news
Also,
/index.php?option=com_content&view=category&layout=blog&id=9&Itemid=104
Changes to /news/sports
SEF URLs Explained/index.php?option=com_content&view=article&id=7&Itemid=103
Changes to /news/7-new-article-2
/index.php?option=com_content&view=article&id=10&Itemid=104
Changes to /news/sports/10-sports-article
Building a Route- Use JRoute::_() to build a route. Pass a URL with an Itemid
- Itemid creates the first section of the SEF URL
- If the query params do not match menu entry query params- The first URL section is created from the menu Itemid. Say /news/sports
- The querystring is passed to extension’s router to build the next part of the route, so it adds /10-sports-article
- This is the right way to build SEF URLs
Building a Route - without Itemid- For URLs without an Itemid, or an invalid Itemid eg: index.php?
option=com_content&view=article&id=7
- JRoute makes this /component/com_content/article/?id=7
- This is the wrong way to build SEF URLs
Itemid guessing- Since JRoute::_() needs an Itemid
- Write a wrapper function, say JTRoute::_() that accepts a part of the URL and guesses the Itemid
- Use this function everywhere to produce consistent URLs
Thanks !Ashwin Date | techjoomla.com | @coolbung