From 5d4de274a8642199f000d2f2415e1acce96f9659 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Tue, 7 Oct 2014 17:58:12 +0200 Subject: [PATCH] Clean-up of mapping routes doc --- usage/mapping-routes.html | 64 +++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/usage/mapping-routes.html b/usage/mapping-routes.html index 1080dd3..741b755 100644 --- a/usage/mapping-routes.html +++ b/usage/mapping-routes.html @@ -16,18 +16,19 @@ layout: default

The map() method accepts the following parameters.

-

$method (string)

+ $method (string)
This is a pipe-delimited string of the accepted HTTP requests methods.

Example: GET|POST|PATCH|PUT|DELETE

-

$route (string)

+ $route (string)
This is the route pattern to match against. This can be a plain string, one of the predefined regex filters or a custom regex. Custom regexes must start with @.

Examples:

+ @@ -51,22 +52,22 @@ layout: default
Route
-

$target (mixed)

-

As AltoRouter leaves handling routes up to you, this can be anything.

+ $target (mixed)
+ As AltoRouter leaves handling routes up to you, this can be anything.

Example using a function callback:
function() { ... } -

-

+

Example using a controller#action string:
UserController#showDetails

-

$name (string, optional)

-

If you want to use reversed routing, specify a name parameter so you can later generate URL's using this route.

+

+ $name (string, optional)
+ If you want to use reversed routing, specify a name parameter so you can later generate URL's using this route.

Example:
- user_details + user_details

Example Mapping

@@ -94,33 +95,36 @@ $router->map( 'POST', '/contact/', 'handleContactForm' );

Match Types

You can use the following limits on your named parameters. AltoRouter will create the correct regexes for you.

-
*                    // Match all request URIs
-[i]                  // Match an integer
-[i:id]               // Match an integer as 'id'
-[a:action]           // Match alphanumeric characters as 'action'
-[h:key]              // Match hexadecimal characters as 'key'
-[:action]            // Match anything up to the next / or end of the URI as 'action'
-[create|edit:action] // Match either 'create' or 'edit' as 'action'
-[*]                  // Catch all (lazy, stops at the next trailing slash)
-[*:trailing]         // Catch all as 'trailing' (lazy)
-[**: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
-
+{% highlight php startinline %} +* // Match all request URIs +[i] // Match an integer +[i:id] // Match an integer as 'id' +[a:action] // Match alphanumeric characters as 'action' +[h:key] // Match hexadecimal characters as 'key' +[:action] // Match anything up to the next / or end of the URI as 'action' +[create|edit:action] // Match either 'create' or 'edit' as 'action' +[*] // Catch all (lazy, stops at the next trailing slash) +[*:trailing] // Catch all as 'trailing' (lazy) +[**: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 +{% endhighlight %}

The character before the colon (the 'match type') is a shortcut for one of the following regular expressions

-
'i'  => '[0-9]++'
-'a'  => '[0-9A-Za-z]++'
-'h'  => '[0-9A-Fa-f]++'
-'*'  => '.+?'
-'**' => '.++'
-''   => '[^/\.]++'
-
+{% highlight php startinline %} +'i' => '[0-9]++' +'a' => '[0-9A-Za-z]++' +'h' => '[0-9A-Fa-f]++' +'*' => '.+?' +'**' => '.++' +'' => '[^/\.]++' +{% endhighlight %}

You can register your own match types using the addMatchTypes() method.

-
$router->addMatchTypes(array('cId' => '[a-zA-Z]{2}[0-9](?:_[0-9]++)?'));
-
+{% highlight php startinline %} +$router->addMatchTypes(array('cId' => '[a-zA-Z]{2}[0-9](?:_[0-9]++)?')); +{% endhighlight %}

Once your routes are all mapped you can start matching requests and continue processing the request.