diff --git a/.gitignore b/.gitignore index d790f42..40e0734 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ _site Gemfile Gemfile.lock +.idea diff --git a/_layouts/default.html b/_layouts/default.html index 6b79f3e..0245105 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -11,6 +11,16 @@ +
examples
directory for a better understanding on how to use AltoRouter.With AltoRouter you define new routes by using the map
method.
map
accepts 4 parameters;
Request methods
+ One of 5 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PATCH|PUT|DELETE)
Route pattern
+ Route pattern to match with. You can use multiple pre-set regex filters, like [i:id]
. A custom regex must start with an @
.
Target
+ The target of where this route should point to. Can be anything.
Name
+ Optional name of this route. Supply if you want to reverse route this url in your application.
$router = new AltoRouter();
-$router->setBasePath('/AltoRouter'); // (optional) the subdir AltoRouter lives in
+// (optional) set basepath to the subdirectory relative to the application root
+// or, a virtual path where you want to integrate AltoRouter.
+$router->setBasePath('/AltoRouter');
-// mapping routes
$router->map('GET|POST','/', 'home#index', 'home');
$router->map('GET','/users', array('c' => 'UserController', 'a' => 'ListAction'));
$router->map('GET','/users/[i:id]', 'users#show', 'users_show');
$router->map('POST','/users/[i:id]/[delete|update:action]', 'usersController#doAction', 'users_do');
// reversed routing
-$router->generate('users_show', array('id' => 5));
+$router->generate('users_show', array('id' => 5)); # => /users/5
+
For quickly adding multiple routes, you can use the addRoutes
method. This method accepts an array or any kind of traversable.
$router->addRoutes(array(
+ array('PATCH','/users/[i:id]', 'users#update', 'update_user'),
+ array('DELETE','/users/[i:id]', 'users#delete', 'delete_user')
+));
You can use the following limits on your named parameters. AltoRouter will create the correct regexes for you.
@@ -80,53 +111,41 @@ layout: defaultSimply call the match() method like this :
+Route lookup is done by calling match
.
-// perform a match against the current request url
-$match = $router->match();
+// perform a match against the current request url
+$result = $router->match();
// perform a match against a given url
-$match = $router->match($url);
-
+$result = $router->match('/path/to/somewhere');
-Structure
+ Return value
-Match return an associative array containing :
+The return value will be an associative array if a match is found and false
otherwise.
-
The array consists of 3 keys; target
, params
and name
.
will give :
+Where target
and name
contain the values passed to map
and params
is an associative array of params extracted from the url.
Array
-(
- [target] => Array
- (
- [c] => UserController
- [a] => Profile
- )
+
+
- [params] => Array
- (
- [id] => 123
- )
+ Example$router = new AltoRouter();
+$router->map('GET', '/user/[i:id]', 'user_controller#show_profile', 'user_profile');
+$result = $router->match('/user/123');
- [name] => userProfile
-)
-
-
+$result == array(
+ 'target' => 'user_controller#show_profile',
+ 'params' => array(
+ 'id' => 123
+ ),
+ 'name' => 'user_profile'
+);
+
Contributors
@@ -141,7 +160,7 @@ layout: default
(MIT License)
-Copyright (c) 2012-2013 Danny van Kooten hi@dannyvankooten.com
+Copyright (c) 2012-2014 Danny van Kooten hi@dannyvankooten.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
diff --git a/stylesheets/styles.css b/stylesheets/styles.css
index dacf2e1..e1f7f81 100644
--- a/stylesheets/styles.css
+++ b/stylesheets/styles.css
@@ -46,7 +46,7 @@ a small {
}
.wrapper {
- width:860px;
+ width:920px;
margin:0 auto;
}
@@ -160,7 +160,7 @@ header ul a strong {
}
section {
- width:500px;
+ width:560px;
float:right;
padding-bottom:50px;
}