2. Anatomy of a non-sef URL
index.php?option=com_content&view=category&layout=blog&id=8&Itemid=103
3. 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
6. 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
7. 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
8. 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