mirror of
https://github.com/dannyvankooten/AltoRouter.git
synced 2025-08-02 06:30:46 +02:00
updated readme
This commit is contained in:
25
README.md
25
README.md
@@ -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)
|
||||||
|
Reference in New Issue
Block a user