Welcome Guest, Not a member yet? Register   Sign In
Odd result from using slash_rsegment
#1

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

[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...
#3

[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).
#4

[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?
#5

[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
#6

[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...
#7

[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?




Theme © iAndrew 2016 - Forum software by © MyBB