Skip to content

Simple routing

JulianFun123 edited this page Jun 22, 2019 · 3 revisions

Simple routing

Routing for example.com/test

$router->set(
   [
    "/test"  =>   "test.php"
   ]
);

Homepath

Routing for example.com/

$router->set(
   [
    "/"  =>   "homepage.php"
   ]
);

Dir routing

Routing for example.com/dir/st

$router->set(
   [
    "/dir/st"  =>   "st.php"
   ]
);

ErrorPages

404

$router->set(
   [
    "@__404__@" => "404.php"
   ]
);

Example

app/route.php

$views_dir = "../views/";
$templates_dir = "../views/templates/";


$route = [
  "/"                      =>   "homepage.php",
  "/about"                 =>   "about.php",
  "/custom/(.*)"           =>   "customtest.php",
  "@__404__@"              =>   "404.php"
];

public/index.php

require "../app/route.php";
require "../devermrouter/Router.php";

$router = new Router($template, $views_dir);
$router->set($route);
$router->route();
Clone this wiki locally