2

What do I understand in Joomla is that until you create a menu for a specific view you will be getting component links to its views, in this manner:

component/component_name/location/new-york (ex #1)

If you create link for this view it should transform to menu alias + view + item name or id, like this:

/locations/location/new-york (ex #2)

However, I did this and I'm still getting an old link like in example #1. Though if I add Itemid to the link I get expected result like in example #2, see below what I mean:

JRoute::_('index.php?option=com_modern_tours&view=location&alias=' . $asset->alias .'&Itemid=138'); this transforms to this /locations/location/new-york

But this

JRoute::_('index.php?option=com_modern_tours&view=location&alias=' . $asset->alias); this transforms to this component/component_name/location/new-york

Seems like in this case I have to create an additional function to search through the menu and add missing itemid. Though I'm unsure if this is really how it should work, or Joomla itself should take of this? Can someone explain this to me, please

1 Answer 1

1

JRoute::_() doesn't find anything. It just turns non-SEF links into SEF. How that is done depends on your component's router. Unless your component implements modern routing (introduced in 3.7, I think), you do need to find the Itemid.

Prior to modern routing, each Joomla core component used its own route helper class to lookup menu items, find the IDs and append them to non-SEF URLs. Modern routing includes this as part of its rule set, so writing this for each component is no longer needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.