CodeIgniter Forums
uri_string() without slash again? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: uri_string() without slash again? (/showthread.php?tid=87127)



uri_string() without slash again? - wine-fine - 03-16-2023

I've updated from 4.2 to 4.3. It seems uri_string() has changed again and now the result is without starting slash as it was some versions before?

in one of the prior updates I had to change code from

$_path = '/'.uri_string() just to $_path = uri_string()

and now back to

$_path = '/'.uri_string()

or do I get something wrong?

Changing such details througout the code would be quite annoying.


RE: uri_string() without slash again? - kenjis - 03-16-2023

Can you tell the exact version that uri_string() returns string with leading slash?
As far as I know nobody changes the behavior like that.

But according to the documentation, uri_string() returns without leading slash:
https://codeigniter4.github.io/CodeIgniter4/helpers/url_helper.html#uri_string
http://www.codeigniter.com/userguide3/helpers/url_helper.html#uri_string

So the current behavior seems correct even if changed.


RE: uri_string() without slash again? - wine-fine - 03-16-2023

(03-16-2023, 05:01 AM)kenjis Wrote: Can you tell the exact version that uri_string() returns string with leading slash?
As far as I know nobody changes the behavior like that.

But according to the documentation, uri_string() returns without leading slash:
https://codeigniter4.github.io/CodeIgniter4/helpers/url_helper.html#uri_string
http://www.codeigniter.com/userguide3/helpers/url_helper.html#uri_string

So the current behavior seems correct even if changed.

sure, its 4.3.2

look at the doc here: https://codeigniter.com/user_guide/helpers/url_helper.html here the leading slash still is included.

So it changed from 4.3.1 to 4.3.2 (?)

makes the code very hard to keep running.


RE: uri_string() without slash again? - kenjis - 03-16-2023

Thank you for reply.

I must have missed, but the following PR seems to have changed the behavior.
https://github.com/codeigniter4/CodeIgniter4/pull/7135

By the way, what are you using code like $_path = '/'.uri_string() for?

uri_string() just returns a part of URI string relative to baseURL.
In other words, it returns a route path (without considering whether there is a leading slash or not).
See https://codeigniter4.github.io/CodeIgniter4/general/urls.html#url-structure

It is not a full URI path, so you cannot use it like <a href="<?= $_path >">.
Because if the baseURL contains a subfolder, the path is wrong.
Of course, it works if the baseURL does not contain a subfolder,
but that is still not the correct usage. If the baseURL changes to have a subfolder,
the code will not work.


RE: uri_string() without slash again? - kenjis - 03-16-2023

In CodeIgniter 3:
public function index()
{
  $this->load->helpers('url');
  var_dump(uri_string());
}


Navigate to http://127.0.0.1:8000/index.php/,
it will returns "string '' (length=0)"

Navigate to http://127.0.0.1:8000/index.php/welcome,
it will returns "string 'welcome' (length=7)"

The uri_string() should return string without leading slash.
So the current behavior in v4.3.2 is correct.


RE: uri_string() without slash again? - kenjis - 03-16-2023

I sent a PR to fix the documentation.
https://github.com/codeigniter4/CodeIgniter4/pull/7356


RE: uri_string() without slash again? - wine-fine - 03-16-2023

(03-16-2023, 06:22 PM)kenjis Wrote: I sent a PR to fix the documentation.
https://github.com/codeigniter4/CodeIgniter4/pull/7356

Fine. Thank you for the explanations and fixing the docs.