1
0
mirror of https://github.com/dannyvankooten/AltoRouter.git synced 2025-08-01 22:20:17 +02:00

updated readme

This commit is contained in:
Danny van Kooten
2012-07-31 21:15:12 +02:00
parent 4e582f163c
commit 14be0eaad0

View File

@@ -1,34 +1,36 @@
**AltoRouter is an alternative router to PHP-Router, also lightning fast and flexible. # AltoRouter
AltoRouter is heavily inspired by [klein.php](https://github.com/chriso/klein.php/). AltoRouter is a small but powerful routing class for PHP 5.3+, heavily inspired by [klein.php](https://github.com/chriso/klein.php/).
* Flexible regular expression routing (inspired by [Sinatra](http://www.sinatrarb.com/)) * Dynamic routing with named parameters
* Reversed routing * Reversed routing
* Named parameter in routes * Flexible regular expression routing (inspired by [Sinatra](http://www.sinatrarb.com/))
## Getting started ## Getting started
1. PHP 5.3.x is required 1. PHP 5.3.x is required
2. Setup URL rewriting so that all requests are handled by **index.php** 2. Setup URL rewriting so that all requests are handled by **index.php**
3. Include AltoRouter, map your routes and match a request. 3. Create an instance of AltoRouter, map your routes and match a request.
4. Have a look at the supplied example file (index.php). 4. Have a look at the supplied example file for a better understanding on how to use AltoRouter(index.php).
## Routing ## Routing
```php ```php
$router = new AltoRouter(); $router = new AltoRouter();
$router->setBasePath('/AltoRouter'); $router->setBasePath('/AltoRouter');
// mapping routes
$router->map('GET|POST','/', 'home#index', array('name' => 'home')); $router->map('GET|POST','/', 'home#index', array('name' => 'home'));
$router->map('GET','/users/', array('c' => 'UserController', 'a' => 'ListAction')); $router->map('GET','/users/', array('c' => 'UserController', 'a' => 'ListAction'));
$router->map('GET','/users/[i:id]', 'users#show', array('name' => 'users_show')); $router->map('GET','/users/[i:id]', 'users#show', array('name' => 'users_show'));
$router->map('POST','/users/[i:id]/[delete|update:action]', 'usersController#doAction', array('name' => 'users_do')); $router->map('POST','/users/[i:id]/[delete|update:action]', 'usersController#doAction', array('name' => 'users_do'));
// reversed routing
$router->generate('users_show', array('id' => 5));
``` ```
You can use the following limits on your named parameters. AltoRouter will create the correct regexes. You can use the following limits on your named parameters. AltoRouter will create the correct regexes.
```php ```php
Some examples
* // Match all request URIs * // Match all request URIs
[i] // Match an integer [i] // Match an integer
[i:id] // Match an integer as 'id' [i:id] // Match an integer as 'id'
@@ -49,6 +51,9 @@ Some more complicated examples
``` ```
## Additional info
If you like AltoRouter, you might also like [PHP Router](//github.com/dannyvankooten/PHP-Router).
## License ## License
(MIT License) (MIT License)