OSDN Git Service

fix psr-0 compliance
[php-libraries/Router.git] / README.md
1 # PHP Router class
2
3 A simple Rails inspired PHP router class.
4
5 * Usage of different HTTP Methods
6 * REST / Resourceful routing
7 * Reversed routing using named routes
8 * Dynamic URL's: use URL segments as parameters.
9
10 ## Usage
11 ```php
12 <?php
13 require 'Router.php';
14 require 'Route.php';
15
16 $router = new Router();
17
18 $router->setBasePath('/PHP-Router');
19
20 // defining routes can be as simple as this
21 $router->map('/', 'users#index');
22
23 // or somewhat more complicated
24 $router->map('/users/:id/edit/', array('controller' => 'SomeController', 'action' => 'someAction'), array('methods' => 'GET,PUT', 'name' => 'users_edit', 'filters' => array('id' => '(\d+)')));
25
26 // You can even specify closures as the Route's target
27 $router->map('/hello/:name', function($name) { echo "Hello $name."; });
28
29 // match current request URL & http method
30 $target = $router->matchCurrentRequest();
31 var_dump($target);
32
33 // generate an URL
34 $router->generate('users_edit', array('id' => 5));
35 ```
36
37 ## More information
38 Have a look at the example.php file or read trough the class' documentation for a better understanding on how to use this class.
39
40 If you like PHP Router you might also like [AltoRouter](//github.com/dannyvankooten/AltoRouter).
41
42 ## License
43 MIT Licensed, http://www.opensource.org/licenses/MIT