The main routing is done in index.php file at the top directory of the project
The available methods are get, post, delete, put.
chdir (dirname (__FILE__));
$rc = include_once ("domframework/route.php");
if ($rc === false)
die ("Please install the domframework !");
session_start ();
$route = new Domframework\Route ();
$route
// Use the GET method and without URL parameter
->get ("", function () use ($route)
{
$route->redirect ("/ipsets", "");
})
// Use the GET method and with URL parameter "ipsets"
->get ("ipsets", function () use ($route)
{
// List all the defined IPSets, with the menu to create/edit/delete one
$route->viewMethod = "listing";
$route->title = _("Defined ipsets");
$ipsetsObj = new \controllers\ipsets ();
return array ("ipsets"=>$ipsetsObj->listSets ());
})
// Use the POST method and with URL parameter "ipsets/add"
->post ("ipsets/add", function () use ($route)
{
// Create really a new ipset
$ipsetsObj = new \controllers\ipsets ();
$form = new Domframework\Form ();
$values = $form->values ();
$errors = $ipsetsObj->verify ($values);
$form->saveValuesErrors ($values, $errors);
if (count ($errors)) $route->redirect ("/ipsets/add");
$ipsetsObj->createSet ($values["setname"], $values["typename"]);
$form->saveValuesErrorsReset ();
$route->redirect ("/ipsets", "");
});
$route
->get ("zone/{zone}/{viewname}/add(\?{fill})?",
function ($zone, $viewname, $fill) use ($route)
{
// Use the $zone, $viewname, $fill variables from the URL
// The fill parameter is optional, and may return null
}
');
Activate the debug by using :
$route = new Domframework\Route ();
$route->debug = 1;
Namespace Domframework
The routing module, base of the DomFramework
Allow slashes in the url when matching the regex
Authentication URL used if a 401 error is raised. If none is defined, just display a "Unauthorized" message
The debug mode : 0:NoDebug, 1:routing, 2:more debug (developpement)
Provide the the class catch errors in routing. Must be provided in an array(class, method);
Filename in views containing the HTML layout. Without .html at the end
The matching route comparison
The method used to ask the page
The module name
Output type to no previous catched renderer (allow : json, xml, txt html)
Preroute used in modules
Ratelimit the errors in route.php to not allow the hackers to brute force the backend. The objct can be put to null to disable the feature
Array to search/replace
Title by default : space to be compatible with HTML5
Array to variable definition
Filename of class containing the presentation layer
Classname containing the error layer
Method apply to class object to display the error
Method apply to class object to display the $result
The route constructor : initialize the parameters
Return the baseURL of the site Always finish with a slash@param string|null $module
The module name (if thereis one)@param boolean|null $absolute
Return the baseURL in absolute@return
string The URL base
Return the baseURL of the module
Always finish with a slash
@return
string The baseURL for the module
Return the baseURL for a resource (add a index.php?url= if there is no
mod_rewrite support. Used to link to modules in the HTML page.
The baseURL is the real base of the project, which is different when not
using the mod_rewrite. They are equal when using the mod_rewrite
@return
string The baseURL for the resource
Define the base URL of the site
@param string $baseURL
The base URL of the site
Get / Set the debug level
@param integer|null $val
The value to set. If null, will return the actual
value
If the URL is corresponding with $url, and the method is DELETE, then the function is called. Ex. : $route->delete ('/hello/{name}', function ($name) { echo "Hello, $name"; });@param string $route
Route to check with the URL@param callable $function
Function to be executed if the route match@return
mixed Exit of the PHP after displaying the page if match, or return the route object to chain it whith the next test
Print an error page. If a custom page exists, use it@param object $e
Exception to print@return
bool true after the error is displayed
If the URL is corresponding with $url, and the method is GET, then the function is called. Ex. : $route->get ('/hello/{name}', function ($name) { echo "Hello, $name"; });@param string $route
Route to check with the URL@param callable $function
Function to be executed if the route match@return
mixed Exit of the PHP after displaying the page if match, or return the route object to chain it whith the next test
Return the last valid get page to return
@return
string The last valid page URL or "" if not set
Redirect to last valid get page if defined
@return
mixed Exit from PHP after redirect or null if the last valid page is not
defined
Do the mapping between the url and the route : call the function if thereis a match@param string $route
Route to check with the URL@param callable $function
Function to be executed if the route match@return
mixed Exit of the PHP after displaying the page if match, or return the route object to chain it whith the next test
Return the mached route search
Return the HTTP method used to connect to the page
Can be override by a _METHOD parameter provided in POST
@return
string the method used to connect
@throws an exception in case of error
Allow multiple methods to execute the function if the route is corresponding to the URL. Ex. : $route->multi("get,post,put,delete,options", '/hello/{name}', function ($name) { echo "Hello, $name"; });@param string $methods
The allowed methods, separated by commas (,)@param string $route
Route to check with the URL@param callable $function
Function to be executed if the route match@return
mixed Exit of the PHP after displaying the page if match, or return the route object to chain it whith the next test
If the URL is corresponding with $url, and the method is OPTIONS, then the function is called. Ex. : $route->options ('/hello/{name}', function ($name) { echo "Hello, $name"; });@param string $route
Route to check with the URL@param callable $function
Function to be executed if the route match@return
mixed Exit of the PHP after displaying the page if match, or return the route object to chain it whith the next test
If the URL is corresponding with $url, and the method is POST, then the function is called. Ex. : $route->post ('/hello/{name}', function ($name) { echo "Hello, $name"; });@param string $route
Route to check with the URL@param callable $function
Function to be executed if the route match@return
mixed Exit of the PHP after displaying the page if match, or return the route object to chain it whith the next test
If the URL is corresponding with $url, and the method is PUT, then the function is called. Ex. : $route->put ('/hello/{name}', function ($name) { echo "Hello, $name"; });@param string $route
Route to check with the URL@param callable $function
Function to be executed if the route match@return
mixed Exit of the PHP after displaying the page if match, or return the route object to chain it whith the next test
Do all the routing with redirections $destURL can be absolute or relative. - absolute : "/main" redirect to "baseURL/mail" - relative : "main" redirect to "./main" If module is set, the site is modular and a directory is named with module name@param string $destURL
Do a redirection of the HTTP page@param string|null $module
The module name@param boolean|null $permanent
Permanent redirect (false by default)@return
mixed mixed Exit of the PHP after doing the redirection
Return the complete URL used to see this page@param boolean|null $absolute
Return the absolute URL@return
string the complete URL used to see this page