Welcome Guest, Not a member yet? Register   Sign In
uri_string() without slash again?
#1

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.
Reply
#2

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/CodeIgnit...uri_string
http://www.codeigniter.com/userguide3/he...uri_string

So the current behavior seems correct even if changed.
Reply
#3

(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/CodeIgnit...uri_string
http://www.codeigniter.com/userguide3/he...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/helpe...elper.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.
Reply
#4

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/CodeIgnit...-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.
Reply
#5

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.
Reply
#6

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

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB