WORK IN PROGRESS - DO NOT USE CURRENT README
A simple router for PHP web applications to add RESTful routes with shallow nesting of resources.
$r = new Router();
$r->resources("users");
Generates the following routes:
Method | Route | Action |
---|---|---|
GET | /users | index |
GET | /users/:id | show |
GET | /users/new | new |
POST | /users | create |
GET | /users/:id/edit | edit |
PUT (as POST) | /users/:id | update |
DELETE (as POST) | /users/:id | destroy |
$r = new Router();
$r->resources("users")->resources("comments");
This will not only match the above 7 routes, but the following 7 too:
Method | Route | Action |
---|---|---|
GET | /users/:id/comments | index |
GET | /comments/:id | show |
GET | /users/:id/comments/new | new |
POST | /users/:id/comments | create |
GET | /comments/:id/edit | edit |
PUT (as POST) | /comments/:id | update |
DELETE (as POST) | /comments/:id | destroy |
As well as plural resources as described above, the router also matches a singular resource:
$r = new Router();
$r->resource("cart")
Method | Route | Action |
---|---|---|
GET | /cart | show |
GET | /cart/new | new |
POST | /cart | create |
GET | /cart/edit | edit |
PUT (as POST) | /cart | update |
DELETE (as POST) | /cart | destroy |
You can also create one off routes - in the following manner
$r->map('/', array('controller' => 'home', 'action' => 'index'));
Using the string ':id' in your route lets you have a placeholder for an alphanumeric id.