Skip to content

omarqureshi/php-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

WORK IN PROGRESS - DO NOT USE CURRENT README

PHP router

A simple router for PHP web applications to add RESTful routes with shallow nesting of resources.

Usage

Simple usage

$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

Shallow nesting example

$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

Singular resource

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

One off routes

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.

About

Rails like router for PHP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages