diff --git a/docs/USAGE b/docs/USAGE index 472fd3a..9b3e8ce 100644 --- a/docs/USAGE +++ b/docs/USAGE @@ -91,15 +91,21 @@ This is the routing. You need to add the routes in your index.php file with : $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 definition match on the HTTP method (GET,POST,PUT or DELETE). It can be +surcharged by using the _METHOD variable in POST method, with the wanted method +to use. The routes are read sequentially. The first which match the class/method wins. +You should carrefully order the rules. +Add the debug on routing with + $route->debug=TRUE; +to help to see the matches. 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 : - array ("route", "redirect", "nextPage/", FALSE), + function () use ($route) {$route->redirect("/home4", FALSE);} If the URL match the requested search, the Web browser will load immediately a new page named "nextPage/". The FALSE will be change in case of modular application (see the MODULAR APPLICATION chapter) diff --git a/route.php b/route.php index ca6d84d..6d80447 100644 --- a/route.php +++ b/route.php @@ -137,7 +137,8 @@ class route - search can be the end of URL and optionnal parameters in {var1} format {var1} must be the name of the parameter of the method - action is an array with (0=>CLASS, 1=>method, 2...=>parameters) */ - function routingCollection ($routes) +// DISABLED FUNCTION : TOO COMPLEX !! + /*function routingCollection ($routes) { if ($this->debug) echo "
==== DEBUG : ROUTING START ====\n";
@@ -251,7 +252,7 @@ class route
echo "URL='";print_r ($url); echo "'\n";
echo "ROUTE='";print_r ($route); echo "'\n";
}*/
-
+/*
// URL === ROUTE (No variables)
if ($url === $route)
@@ -388,12 +389,23 @@ class route
// TODO : ERROR 404 !
echo "404";
return;
- }
+ }*/
/** Return the HTTP method used to connect to the page
+ Can be override by a _METHOD parameter provided in POST
Throw an exception in case of error */
public function method ()
{
+ if (isset ($_POST["_METHOD"]) &&
+ ($_POST["_METHOD"] === "GET" ||
+ $_POST["_METHOD"] === "POST" ||
+ $_POST["_METHOD"] === "PUT" ||
+ $_POST["_METHOD"] === "DELETE"))
+ {
+ $this->method = $_POST["_METHOD"];
+ return $_POST["_METHOD"];
+ }
+
if (!isset ($_SERVER["REQUEST_METHOD"]))
throw new Exception ("No REQUEST_METHOD", 415);
if ($_SERVER["REQUEST_METHOD"] === "GET" ||
@@ -474,7 +486,7 @@ class route
{
if ($this->debug)
echo "==> DELETE $route ?? ";
- if ($this->method () !== " DELETE")
+ if ($this->method () !== "DELETE")
{
if ($this->debug)
echo "==> Not a DELETE Method\n";