Welcome Guest, Not a member yet? Register   Sign In
To trim or not to trim / ? That's the question (CI_URI)
#1

[eluser]dirkpostma[/eluser]
I found out that the URI detection in CI_URI has gone through a major rewrite in CI 2.0.0 and that the behaviour has change. My code is partially broken because of that.

I also found the cause. In CI 2.0.0 slashes are are trimmed in line 179 of CI_URI.php

Code:
return str_replace(array('//', '../'), '/', trim($uri, '/'));

This means that the behaviour has changed, as in CI 1.7.2 this trimming is not executed.

The manual says:

Quote:$this->uri->uri_string()

Returns a string with the complete URI. For example, if this is your full URL:
http://example.com/index.php/news/local/345

The function would return this:
/news/local/345

..but because of the trimming of slashes, this is not the case anymore. The result will be:

Quote:news/local/345

I want to adapt my code for the future, but I don't know what the behaviour should be. The behaviour according according to the current code or acoording to the manual?

In other words, what will the future be? To trim or not trim /'s?
#2

[eluser]dirkpostma[/eluser]
This fix works for me:

Code:
<?php

class MY_URI extends CI_URI
{

  function MY_URI()
  {
    parent::__construct();
  }

  function uri_string()
  {
    // Make sure the result always starts with a /
    // no matter which CI version you use (1.7.2 or 2.0.0)
    $res = trim(parent::uri_string(), '/');
    return "/" . $res;
  }
}
?>


NB: Save this code in {your_application_path}/core/MY_URI.php (NOT in {your_application_path}/libraries didn't work for me)




Theme © iAndrew 2016 - Forum software by © MyBB