1 # Simple PHP Router class
3 A simple Router class that supports REST routing, named routes and reverse routing.
12 // maps / to controller 'users' and method 'index'.
13 $r->match('/','users#index');
15 // maps /user/5 to controller 'users', method 'show' with parameter 'id' => 5
16 $r->match('/user/:id','users#show');
18 // maps POST request to /users/ to controller 'users' and method 'create'
19 $r->match('/users','users#create',array('via' => 'post'));
22 // maps GET /users/5/edit to controller 'users', method 'edit' with parameters 'id' => 5 and saves route as a named route.
23 $r->match('/user/:id/edit','users#edit',array('via' => 'get', 'as' => 'user_edit_page'));
25 // echoes /users/5/edit
26 echo $r->reverse('user_edit_page',array('id' => '5'));
28 // maps multiple routes
29 // GET /users will map to users#index
30 // GET /users/5 will map to users#show
31 $r->resources('users',array('only' => 'index,show'));
35 // extract controller, action and parameters.
36 extract($r->getRoute());
40 <p><b>Controller: </b><?php echo $controller; ?></p>
41 <p><b>Action: </b><?php echo $action; ?></p>
42 <p><b>Params: </b><?php var_dump($params); ?></p>
46 ?><h1>No route found.</h1><?php
49 Have a look at example.php or read trough the class' documentation for a better understanding on how to use this class.