This is easy-to-use php component for routing URLs in your project. See index.php
for examples.
run()
- runs routing
index.php
$config = require __DIR__ . '/Router/config.php';
config.php
'tplpath' => __DIR__ . '/../templates/',
'routes' => [
'' => 'index',
'/login' => 'login',
'/profile' => 'profile',
]
A file must be called 2nd_part_of_route.view.php
. For example we have a route '/about' => 'about_us'
therefore the file must be about_us.view.php
and be placed into templates
folder (tplpath
parameter). If a file cannot be found Router shows 404.view.php
from templates
folder.
templates/
404.view.php
index.view.php
login.view.php
require __DIR__ . '/Router/Router.php';
$router = new Router($config['routes'], $config['tplpath']);
$router->run();