CodeIgniter Forums
Odd result from using slash_rsegment - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Odd result from using slash_rsegment (/showthread.php?tid=6282)



Odd result from using slash_rsegment - El Forum - 02-21-2008

[eluser]adamp1[/eluser]
Right I have a controller (admin/settings) and need to fetch the segment information. So I tried using $this->uri->segment(). Problem is I also have the following route
Code:
admin => admin/home
So I tried to construct the uri string using rsegment(). The reason I can't use uri_string() is becasue I don't need all the segments all the time.

Now a strange thing happens, If I am at index.php/admin/settings and run the following code:
Code:
$this->CI->uri->slash_rsegment(1) .
$this->CI->uri->slash_rsegment(2) .
$this->CI->uri->slash_rsegment(3);
I only get this settings/index// but if I run this code:
Code:
$this->CI->uri->slash_segment(1) .
$this->CI->uri->slash_rsegment(1) .
$this->CI->uri->slash_rsegment(2);
I get the result I want admin/settings/index. I don't get why slash_rsegment and slash_segment seem to work differently.


Odd result from using slash_rsegment - El Forum - 02-21-2008

[eluser]Clooner[/eluser]
I think it has to do with the routing features...

Rsegment returns the routed segments and the normal segments returns the unrouted (what is in your url path segments...


Odd result from using slash_rsegment - El Forum - 02-21-2008

[eluser]adamp1[/eluser]
I know that, but surely the route shouldn't apply since a controller was specified. I don't get why slash_segment(1) dosn't return the same as slash_rsegment(1).


Odd result from using slash_rsegment - El Forum - 02-21-2008

[eluser]Clooner[/eluser]
$this->CI->uri->slash_segment(1) .
$this->CI->uri->slash_rsegment(1) .
$this->CI->uri->slash_rsegment(2);

Returns the first segment of the unrouted segments and the first and second of the routed segments.

You have a route something like this: admin/settings => settings/index?

What is the exact problem you are having?


Odd result from using slash_rsegment - El Forum - 02-21-2008

[eluser]adamp1[/eluser]
No, read the first post again, I have a route admin => admin/home so when going to admin/settings this route should not be taken into account since a controller is given.

If I am at index.php/admin/settings:

The problem I am having is slash_rsegment(1) returns settings instead of admin


Odd result from using slash_rsegment - El Forum - 02-21-2008

[eluser]Clooner[/eluser]
So there is no routing used for this? It just uses the default routing right? maybe that is the problem because rsegments is only used for re-routed segments...


Odd result from using slash_rsegment - El Forum - 02-22-2008

[eluser]adamp1[/eluser]
But surely in both cases the first segment of the route is never changed routed or non-routed so it should return the same value?