Add a new routing module with easier support. It understand the RESTful mode too with GET,PUT,POST,DELETE.

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1209 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-02-27 15:04:20 +00:00
parent a437f8e62a
commit 6ce3776d12
2 changed files with 141 additions and 8 deletions

View File

@@ -86,16 +86,16 @@ you will allow the class "blog" to be launch with the parameter "page".
This is the routing. You need to add the routes in your index.php file with :
require_once ("domframework/route.php");
$route = new route ();
$res = $route->routingCollection (array (
"blog/{page}" => array ("class", "method", "{page}"),
));
$route->get ("home", function () { echo "YESY"; });
$route->post ("home", function () { echo "YESY"; });
$route->put ("home", function () { echo "YESY"; });
$route->delete ("home", function () { echo "YESY"; });
The definition match on the HTTP method (GET,POST,PUT or DELETE).
The routes are read sequentially. The first which match the class/method wins.
It start a new instance of "class" and apply the method "method" with the
parameters need to launch the action. The result of the action is returned to
the main script to be outputed.
The parameters are puts between {}. You must put the parameters in the right
order needed by your method.
We can use some variables to be passed to the called function :
$route->get ("home3/{plo}/{str}", function ($str, $plo) {echo "$str $plo";});
There is a special action named "redirect" in the "route" class. It provide the
capability to re-route the Web browser to another page. Put in action :