mirror of
https://github.com/dannyvankooten/AltoRouter.git
synced 2025-08-03 06:57:46 +02:00
Updated README to include addMatchTypes
This commit is contained in:
59
README.md
59
README.md
@@ -30,28 +30,49 @@ $router->generate('users_show', array('id' => 5));
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
You can use the following limits on your named parameters. AltoRouter will create the correct regexes for you.
|
**You can use the following limits on your named parameters. AltoRouter will create the correct regexes for you.**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
* // 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'
|
||||||
[a:action] // Match alphanumeric characters as 'action'
|
[a:action] // Match alphanumeric characters as 'action'
|
||||||
[h:key] // Match hexadecimal characters as 'key'
|
[h:key] // Match hexadecimal characters as 'key'
|
||||||
[:action] // Match anything up to the next / or end of the URI as 'action'
|
[:action] // Match anything up to the next / or end of the URI as 'action'
|
||||||
[create|edit:action] // Match either 'create' or 'edit' as 'action'
|
[create|edit:action] // Match either 'create' or 'edit' as 'action'
|
||||||
[*] // Catch all (lazy, stops at the next trailing slash)
|
[*] // Catch all (lazy, stops at the next trailing slash)
|
||||||
[*:trailing] // Catch all as 'trailing' (lazy)
|
[*:trailing] // Catch all as 'trailing' (lazy)
|
||||||
[**:trailing] // Catch all (possessive - will match the rest of the URI)
|
[**:trailing] // Catch all (possessive - will match the rest of the URI)
|
||||||
.[:format]? // Match an optional parameter 'format' - a / or . before the block is also optional
|
.[:format]? // Match an optional parameter 'format' - a / or . before the block is also optional
|
||||||
|
|
||||||
Some more complicated examples
|
|
||||||
@/(?[A-Za-z]{2}_[A-Za-z]{2})$ // custom regex, matches language codes like "en_us" etc.
|
|
||||||
/posts/[*:title][i:id] // Matches "/posts/this-is-a-title-123"
|
|
||||||
/output.[xml|json:format]? // Matches "/output", "output.xml", "output.json"
|
|
||||||
/[:controller]?/[:action]? // Matches the typical /controller/action format
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Some more complicated examples**
|
||||||
|
|
||||||
|
```php
|
||||||
|
@/(?[A-Za-z]{2}_[A-Za-z]{2})$ // custom regex, matches language codes like "en_us" etc.
|
||||||
|
/posts/[*:title][i:id] // Matches "/posts/this-is-a-title-123"
|
||||||
|
/output.[xml|json:format]? // Matches "/output", "output.xml", "output.json"
|
||||||
|
/[:controller]?/[:action]? // Matches the typical /controller/action format
|
||||||
|
```
|
||||||
|
|
||||||
|
**The character before the colon (the 'match type') is a shortcut for one of the following regular expressions**
|
||||||
|
|
||||||
|
```php
|
||||||
|
'i' => '[0-9]++'
|
||||||
|
'a' => '[0-9A-Za-z]++'
|
||||||
|
'h' => '[0-9A-Fa-f]++'
|
||||||
|
'*' => '.+?'
|
||||||
|
'**' => '.++'
|
||||||
|
'' => '[^/\.]++'
|
||||||
|
```
|
||||||
|
|
||||||
|
**New match types can be added using the `addMatchTypes()` method**
|
||||||
|
|
||||||
|
```php
|
||||||
|
$router->addMatchTypes(array('cId' => '[a-zA-Z]{2}[0-9](?:_[0-9]++)?'));
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
- [Danny van Kooten](https://github.com/dannyvankooten)
|
- [Danny van Kooten](https://github.com/dannyvankooten)
|
||||||
- [Koen Punt](https://github.com/koenpunt)
|
- [Koen Punt](https://github.com/koenpunt)
|
||||||
|
Reference in New Issue
Block a user