1

I'm developing a component in Joomla! 3.9.13 with SEF urls turned ON and I use this line of code

JRoute::link(
'site',
'index.php?option=com_mycomponent&task=profile.edit',
false,
JRoute::TLS_IGNORE,
true
)

and - depending on the application context - it generates two different urls. When called from within the 'administrator' context I get

http://mysite.com/index.php/component/mycomponent/?task=profile.edit

When using it in the 'site' app, I get

http://mysite.com/index.php/mycomponent_translated?task=profile.edit

I've read that the first parameter 'site' would force Joomla! to use the site context but obviously it doesn't work. I couldn't find a clear answer to this, especially not for the current Joomla! version 3.9.x so I'd be grateful if anybody could shed some light on this.

5
  • 1
    Just a few questions for clarification. I presumed you've developed a custom router for your component, have you? Is it all working ok? Is it using the new Joomla router mechanism or the old one? The position of the "index.php" in the URL path makes me suspect that something in the router isn't right. Where does the "mycomponent_translated" string come from? (I've checked on my own instance with a component I developed and it's giving me the same URL on both admin and site). – Robbie Jackson Feb 6 '20 at 9:44
  • Thanks @RobbieJackson, I didn't know I had to code a router to make this work. I expected to get identical results when performing identical function calls. Could you point me to a resource where I can get started and find some explanation to the old an the new Joomla router mechansim? – Rico Feb 10 '20 at 11:16
  • 1
    The main purpose of the router is to enable your component to work well with SEF URLs. You can find some info about it in docs.joomla.org/J3.x:Supporting_SEF_URLs_in_your_component and the Joomla MVC tutorial works through developing one in docs.joomla.org/J3.x:Developing_an_MVC_Component/…, docs.joomla.org/J3.x:Developing_an_MVC_Component/… and docs.joomla.org/J3.x:Developing_an_MVC_Component/…. – Robbie Jackson Feb 10 '20 at 22:01
  • 1
    Info on the new router at groups.google.com/forum/#!msg/joomla-dev-general/YnILNx_Lmeg/… but I tried to get this to work with the Joomla MVC tutorial and failed. It's a rule-based router, but often the problem with rule interpreters is trying to debug the code when things don't go right. – Robbie Jackson Feb 10 '20 at 22:10
  • 1
    I think the main issue here is that Itemid is missing from your url. When you build the url from the front end your router most likely defaults to the active menu item. From admin there is no active menu item so it defaults to no menu item. Hence the diffference. You may want to search for a menu item in your router’s build method if none was specified. – ulvesked Apr 11 '20 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.