I'm trying to achieve the following URLs for my API (I'm using Codeigniter and Phil Sturgeon's REST server library):
/players -> refers to index method in the players controller
/players/rookies -> refers to rookies method in the players controller
I don't want the URL to have a trailing "index"
/players/index
This is no problem at all when I define the routes like so:
$route['players'] = 'players/index';
Everything works as expected.
My problem is that I need additional URL segments like so:
/players/rookies/limit/10/offset/5/key/abcdef
The above example works, but the following does not:
/players/limit/10/offset/5/key/abcdef
I'm getting the following error: {"status":false,"error":"Unknown method."}
Obviously there is no limit
method in my controller.
How do I have to setup my routes.php config file to get these URLs to work properly?
Any help is much appreciated!
gregory, as you're stating yourself "/players refers to index method in the players controller", that means you shouldn't need to have $route['players'] = 'players/index' if your routing is clean.
You can have as many segments as you want and get URI class to distinguish them in your script. That means this URL "/players/rookies/limit/10/offset/5/key/abcdef" by default should lead to your players controller, rookies() method. And here's how you can get your segments:
In addition for /players/limit to work:
Edit 1
Here's another approach:
Routing rules:
In controller