Ali
Ali

Reputation: 267317

Codeigniter route help

I need a codeigniter route so all of the following urls:

admin/users/page/:num
admin/accounts/page/:num
members/results/page/:num
products/page/:num

are forwarded to

admin/users/index
admin/accounts/index
members/results/index
products/index

respectively. I'd like just one regexp which could do the trick rather than me setting the routes manually each time.

To be specific, any url which ends in page/:num should be forwarded to its respective controller's index method. And by :num I mean any number.

Is this possible?

Upvotes: 3

Views: 2178

Answers (1)

andyk
andyk

Reputation: 10008

I don't really get why you would want to do that. (I assume that you want to get the page number from the URL instead)

add these lines to your system/application/config/routes.php (couldn't think of a one-line solution) :

$route['([a-z]+)/page/:num'] = "$1/index";
$route['([a-z]+)/([a-z]+)/page/:num'] = "$1/$2/index";

cmiiw.

Upvotes: 4

Related Questions