Welcome Guest, Not a member yet? Register   Sign In
Routing question
#1

[eluser]Volder[/eluser]
hello

I am facing the following problem:

I have controller called 'Main', there I have a function 'test':
Code:
function test()
       {
         print_r($this->uri->segments);
         echo "<br />";
         print_r($this->uri->rsegments);
         echo "<br />";
         echo "hello, Wolrd";
       }

in the routes config I have:
Code:
$route['test(/.*|$)'] = 'main/test$1';
$route['(.*)/page([0-9]+)$'] = '$1/page/$2';

what I want to achieve is when I input:
Code:
mysite_url/test/page3
I would be rerouted to
Code:
mysite_url/main/test/page/3
but I am sent to
Code:
mysite_url/main/test/page3
that means the second routing instruction is not triggering for me.

in the user_guide I read that:
Quote:Note: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.
and I understand this in the way that my first instruction will transform:
Code:
mysite_url/test/page3 => mysite_url/main/test/page3
and second:
Code:
mysite_url/main/test/page3 => mysite_url/main/test/page/3
but seems it doesn't.

can anyone help one this?
#2

[eluser]devbro[/eluser]
not quite sure, but i guess that routing is order dependent. only one routing is done per each request. try to move the second route to the first place.
#3

[eluser]bitist[/eluser]
Yes, only one router is executed (in the higher position):
$route['test(/.*|$)'] = 'main/test$1';
to
mysite_url/main/test/page3
#4

[eluser]Volder[/eluser]
does it mean - that two routing rules could never be applied both during one request?
and if I want to make both transformations - I need to put it inside one rule?
#5

[eluser]bitist[/eluser]
Two (or more) routes never will be applied for one request.
Yes, you should put inside one rule.
#6

[eluser]Volder[/eluser]
ok, thanks




Theme © iAndrew 2016 - Forum software by © MyBB