JURI::root() getting wrong path Topic is solved
Moderators: ooffick, General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
-
- Joomla! Enthusiast
- Posts: 142
- Joined: Wed Aug 11, 2021 12:44 pm
JURI::root() getting wrong path
I have a link to my website "www.example/dev/index.php". But when I use JURI:root() . '/index.php' the link that I get back is "www.example/index.php" instead of "www.example/dev/index.php". The website is currently under development and it will break once the website is migrated and no longer contain "/dev" in the URL.
I would like to know how I can get the value for anything before the "/index.php" . Can any kind souls help me out here ?
I would like to know how I can get the value for anything before the "/index.php" . Can any kind souls help me out here ?
Last edited by imanickam on Tue Sep 28, 2021 2:50 pm, edited 1 time in total.
Reason: Moved topic » from General Questions/New to Joomla! 4.x to Joomla! 4.x Coding
Reason: Moved topic » from General Questions/New to Joomla! 4.x to Joomla! 4.x Coding
-
- Joomla! Hero
- Posts: 2897
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: JURI::root() getting wrong path
Do you have live_site set in configuration.php? Any extensions installed? Is website working properly, are stylesheets loading properly?
-
- Joomla! Enthusiast
- Posts: 142
- Joined: Wed Aug 11, 2021 12:44 pm
Re: JURI::root() getting wrong path
No I don't have live_site set in configuration.php, it's value is empty. Everything about the website is working fine. Just that when the user make a booking I would sent them an email with a link to cancel their booking such as 'https://example.com/dev/index.php?optio ... ancelorder' but the problem is I am getting 'https://example.com/index.php?option=ta ... ancelorder' without the /dev. I would like to know how can I get the path before the /index.php
- ceford
- Joomla! Hero
- Posts: 2654
- Joined: Mon Feb 24, 2014 10:38 pm
- Location: Edinburgh, Scotland
- Contact:
Re: JURI::root() getting wrong path
If you use URI::root(true); you get the path to your site without the domain - but you have to append '/' yourself. With URI::root(); you get the domain and path. I have different paths on localhost, a development site and a production site and I have never seen your problem. I doubt whether using JURI rather than URI makes a difference - but check.
-
- Joomla! Hero
- Posts: 2897
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: JURI::root() getting wrong path
I can't reproduce the issue either, JUri::root() should include the path.How about those extensions? Maybe a rogue JUri::root(false, '') call is made somewhere, setting an empty path. Although then things like stylesheets would be broken unless call was made very late.
Can you check if JRoute::link() is working? Like so:
Can you check if JRoute::link() is working? Like so:
Code: Select all
JRoute::link('site', 'index.php?option=com_foo&task=cancelorder', false, JRoute::TLS_IGNORE, true);
-
- Joomla! Enthusiast
- Posts: 142
- Joined: Wed Aug 11, 2021 12:44 pm
Re: JURI::root() getting wrong path
Hi, I tried changing it to URI::root(true) but it gives the same result as JURI::root()ceford wrote: ↑Wed Sep 22, 2021 8:32 amIf you use URI::root(true); you get the path to your site without the domain - but you have to append '/' yourself. With URI::root(); you get the domain and path. I have different paths on localhost, a development site and a production site and I have never seen your problem. I doubt whether using JURI rather than URI makes a difference - but check.
-
- Joomla! Enthusiast
- Posts: 142
- Joined: Wed Aug 11, 2021 12:44 pm
Re: JURI::root() getting wrong path
I apologize, if I was not clear. I have attached my code in code.txt. You can see that I am setting $root_link = URI::root(true) (previously was JURI::root()). and then setting the $cancellink = $root_link . 'index.php....'
The expected value I want for $cancellink should be 'www.example.com/dev/index.php...' but I am getting
'www.example.com/index.php...' instead.
The expected value I want for $cancellink should be 'www.example.com/dev/index.php...' but I am getting
'www.example.com/index.php...' instead.
You do not have the required permissions to view the files attached to this post.
- ceford
- Joomla! Hero
- Posts: 2654
- Joined: Mon Feb 24, 2014 10:38 pm
- Location: Edinburgh, Scotland
- Contact:
Re: JURI::root() getting wrong path
This part looks wrong: task=default_cancelorder
It should be task=controller.function - so task=default.cancelorder but default looks wrong too - unless that is the actual name of a controller.
To be honest the whole piece of code looks unfamiliar to me - suspicious even.
It should be task=controller.function - so task=default.cancelorder but default looks wrong too - unless that is the actual name of a controller.
To be honest the whole piece of code looks unfamiliar to me - suspicious even.
-
- Joomla! Hero
- Posts: 2897
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: JURI::root() getting wrong path
if($root_link == "") condition doesn't pass under normal circumstances (when site is accessed over webserver and server is configured properly). What you can do is remove the conditional and always add the path. Or simplify the code like this:
Code: Select all
$cancellink = JUri::root() . "index.php?option=com_osservicesbooking&task=default_cancelorder&id=" . $orderId . "&ref=" . md5($orderId);
-
- Joomla! Enthusiast
- Posts: 142
- Joined: Wed Aug 11, 2021 12:44 pm
Re: JURI::root() getting wrong path
Thanks everyone for trying to help, you guys helped to narrow down the scope of error. After looking at my code line by line carefully. Turns out the str_replace() 1st parameter value was not even in the url and the second parameter will change it to and empty string. Because of this, the "/dev" disappears. After removing the str_replace() line of code, everything started to work perfectly.
-
- Joomla! Hero
- Posts: 2897
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: JURI::root() getting wrong path
There was no str_replace() in your posted code .
-
- Joomla! Enthusiast
- Posts: 142
- Joined: Wed Aug 11, 2021 12:44 pm