OSDN Git Service

c453bec2c51479f9b578f2450ac7a9cf11db7f4c
[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
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'));
25
26     // match current request URL & http method
27     $target = $router->matchCurrentRequest();
28     var_dump($target);
29
30    // generate an URL 
31    $router->generate('users_edit', array('id' => 5));
32
33
34 ## More information
35 Have a look at the example.php file or read trough the class' documentation for a better understanding on how to use this class.