Part on routers finished
This commit is contained in:
parent
a1e1a43d81
commit
8bb5f373f8
8 changed files with 68 additions and 9 deletions
28
index.php
28
index.php
|
|
@ -1,4 +1,26 @@
|
|||
<?php
|
||||
require 'functions.php';
|
||||
$heading = "Home";
|
||||
require "views/index.view.php";
|
||||
require 'functions.php';
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'])['path'];
|
||||
|
||||
$routes = [
|
||||
'/' => 'controllers/index.php',
|
||||
'/about' => 'controllers/about.php',
|
||||
'/contact' => 'controllers/contact.php',
|
||||
'/mission' => 'controllers/mission.php',
|
||||
];
|
||||
|
||||
function routeToController($uri, $routes) {
|
||||
if (array_key_exists($uri, $routes)) {
|
||||
require $routes[$uri];
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
routeToController($uri, $routes);
|
||||
|
||||
function abort($code = 404) {
|
||||
http_response_code($code);
|
||||
require "views/{$code}.php";
|
||||
die();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue