$router = new Router();
- $router->setBasePath('/rest-router');
+ $router->setBasePath('/PHP-Router');
- // maps / to controller 'users' and method 'index'.
- $router->map('/', 'users#index', array('methods' => 'GET'));
- $router->map('/users/:id/edit/', 'users#edit', array('methods' => 'GET', 'name' => 'user_edit_page'));
+ // defining routes can be as simple as this
+ $router->map('/', 'users#index');
- $params = $router->matchCurrentRequest();
- var_dump($params);
+ // or somewhat more complicated
+ $router->map('/users/:id/edit/', array('controller' => 'SomeController', 'action' => 'someAction'), array('methods' => 'GET,PUT', 'name' => 'users_edit'));
- ?><h3>Reversed routing</h3><?php
- // echoes /users/5/edit
- echo "Route for user_edit_page with ID 5: ". $router->reverse('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));
## More information
-Have a look at the example file or read trough the class' documentation for a better understanding on how to use this class.
\ No newline at end of file
+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
$router->map('/', 'someController:indexAction', array('methods' => 'GET'));
$router->map('/users/:id/edit/', 'users#edit', array('methods' => 'GET', 'name' => 'users_edit'));
$router->map('/contact/',array('controller' => 'someController', 'action' => 'contactAction'), array('name' => 'contact'));
-$router-> map('/users/','users#create', array('methods' => 'POST', 'name' => 'users_create'));
-$router-> map('/users/','users#list', array('methods' => 'GET', 'name' => 'users_list'));
+$router->map('/users/','users#create', array('methods' => 'POST', 'name' => 'users_create'));
+$router->map('/users/','users#list', array('methods' => 'GET', 'name' => 'users_list'));
?><h3>Current URL & HTTP method would route to: </h3>
<pre><?php var_dump($router->matchCurrentRequest()); ?></pre>
<h3>Try out these URL's.</h3>
-
<p><a href="<?php echo $router->generate('users_edit', array('id' => 5)); ?>"><?php echo $router->generate('users_edit', array('id' => 5)); ?></a></p>
<p><a href="<?php echo $router->generate('contact'); ?>"><?php echo $router->generate('contact'); ?></a></p>
<p><form action="" method="POST"><input type="submit" value="Post request to current URL" /></form></p>