Welcome Guest, Not a member yet? Register   Sign In
$this->uri->rsegments versus $this->uri->segments: subdirectory gets lost?
#1

[eluser]uprocka[/eluser]
Hello I use the resegment(n) function to get data from the routed uri.

the problem is when there wasn a routing the VAR $this->uri->rsegments holds different data than $this->uri->segments - that seems to be wrongto me.

Code:
URI: /index.php/admin/order/1000/invoice/
//no routing defined in routes.php!

print_r($this->uri->segments);
// Array ( [1] => admin [2] => order [3] => 1000 [4] => invoice )

print_r($this->uri->rsegments);
// Array ( [1] => order [2] => 1000 [3] => invoice )
#2

[eluser]kenjis[/eluser]
Yes, you're.

This seems to be a bug.


And my friend found the below result:
Code:
URI: /index.php/admin/

print_r($this->uri->segments);
// Array ( [1] => admin )

print_r($this->uri->rsegments);
// Array ( )
#3

[eluser]uprocka[/eluser]
the bug is still present in 1.6.3


Is there an offcial bugfix? Could not find one...
Should I post it to the bugtracker?
#4

[eluser]Derek Allard[/eluser]
rsegment is intended to be used "in the event you are using CodeIgniter's URI Routing feature." If routing isn't being used, does it still make sense that rsegment be available? If you still think so (I'm not sure, my knee jerk is that it shouldn't but I'm open to having my mind changed) do you have a proposed code change?
#5

[eluser]Colin Williams[/eluser]
I'm kinda with you Derek. If I improperly use rsegment but don't see the err of my ways, I might be going batty when I actually do set up a route for this context. Might be good to leave the awkward handling, or even return FALSE if there is no route to parse.
#6

[eluser]Michael Wales[/eluser]
To be honest, I've never had a need for rsegment...

If I have the following URL: domain.com/walesmd
and I am using routing to push it to: users/view/walesmd

My function would be:

Code:
function view($username = NULL) {
  echo $username . ' or ';
  echo $this->uri->segment(1);
}

Never had any problems thus far...




Theme © iAndrew 2016 - Forum software by © MyBB