OSDN Git Service

Updated readme for 1.1
[php-libraries/Router.git] / README.md
index 44ce367..c453bec 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,41 +1,35 @@
-# Simple PHP Router class
+# PHP Router class
 
-A simple Router class that supports REST routing, named routes and reverse routing. 
+A simple Rails inspired PHP router class.
+
+* Usage of different HTTP Methods
+* REST / Resourceful routing
+* Reversed routing using named routes
+* Dynamic URL's: use URL segments as parameters.
 
 ## Usage
 
     <?php
     require 'Router.php';
+    require 'Route.php';
 
-    $r = new Router();
-
-    // maps / to controller 'users' and method 'index'.
-    $r->match('/','users#index');
-
-    // maps /user/5 to controller 'users', method 'show' with parameter 'id' => 5
-    $r->match('/user/:id','users#show');
+    $router = new Router();
 
-    // maps POST request to /users/ to controller 'users' and method 'create'
-    $r->match('/users','users#create',array('via' => 'post'));
+    $router->setBasePath('/PHP-Router');
 
+    // defining routes can be as simple as this
+    $router->map('/', 'users#index');
 
-    // maps /users/5/edit to controller 'users', method 'edit' with parameters 'id' => 5.
-    $r->match('/user/:id/edit','users#edit',array('via' => 'get', 'as' => 'user_edit_page'));
+    // or somewhat more complicated
+    $router->map('/users/:id/edit/', array('controller' => 'SomeController', 'action' => 'someAction'), array('methods' => 'GET,PUT', 'name' => 'users_edit'));
 
-    // echoes /users/5/edit
-    echo $r->url_for_route('user_edit_page',array('id' => '5'));
+    // match current request URL & http method
+    $target = $router->matchCurrentRequest();
+    var_dump($target);
 
+   // generate an URL 
+   $router->generate('users_edit', array('id' => 5));
 
-    if($r->hasRoute()) {
-        extract($r->getRoute());
-        ?>
-        <h1>Route found!</h1>
-        <p><b>Controller: </b><?php echo $controller; ?></p>
-        <p><b>Action: </b><?php echo $action; ?></p>
-        <p><b>Params: </b><?php var_dump($params); ?></p>
-        <?php
-    } else {
-        ?><h1>No route found.</h1><?php
-    }
 
-Have a look at example.php or read trough the class' documentation for a better understanding on how to use this class.
\ No newline at end of file
+## More information
+Have a look at the example.php file or read trough the class' documentation for a better understanding on how to use this class.
\ No newline at end of file