CodeIgniter Forums
Routing Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Routing Problem (/thread-31310.html)



Routing Problem - El Forum - 06-14-2010

[eluser]Aidy[/eluser]
I have a route setup like

Code:
$route['Resource-Centre/Catalogue/(:any)/(:any)/(:any)/(:any)/(:any)/(:any)/(:any)/(:num)/(:num)'] = 'resource-centre/catalogue/$1/$2/$3/$4/$5/$6/$7/$8/$9';

The last two wildcards are for pagination (I'm using the digg style pagination library).

This works fine on our test server setup but on the live site it's throwing a 404 if their are no pagination values. It works fine if their are.

Can anyone help please.


Routing Problem - El Forum - 06-14-2010

[eluser]n0xie[/eluser]
It's because it expects to find 2 more arguments that are of type 'num'. If there aren't any arguments, the rule isn't executed.

Why not just do
Code:
$route['Resource-Centre/Catalogue/(:any)'] = 'resource-centre/catalogue/$1';
and check for paging variables inside your method?


Routing Problem - El Forum - 06-14-2010

[eluser]mddd[/eluser]
Logical. If the last two items are not numbers, the route does not match. If you want to match the route even if there are no numbers at the end, you need to change the route so it still matches without the numbers.
In this case, I would suggest making the route simply
Code:
$route['Resource-Centre/Catalogue(.*)'] = 'resource-centre/catalogue$1';
and then checking in the controller (for instance in the constructor method) which information is requested exactly.
Or if you make your urls all lowercase, you wouldn't even need the route.

Edit:Exactly what n0xie said.


Routing Problem - El Forum - 06-14-2010

[eluser]Aidy[/eluser]
Thank you n0xie and mddd.

That's working now and all makes sense now!