Back to the module list

Routing

The main routing is done in index.php file at the top directory of the project

Basic routing

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 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 \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", "");
});

Routing with variable parameters

$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
}
');

Debug the routing analysis

Activate the debug by using :

$route = new route ();
$route->debug = 1;