This repository was archived by the owner on Apr 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
62 lines (48 loc) · 1.49 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require_once("Classes/Router.php");
require_once("Classes/ViewEngine.php");
$Router = new Router();
$ViewEngine = new ViewEngine();
$documentRoot = $_SERVER['DOCUMENT_ROOT'];
$route = "/";
if (isset($_GET['route'])){
$route = $_GET['route'];
}
if (trim($route) == ""){
$route = "/";
}
if (substr($route, 0, 1) != "/"){ // Prepend a missing slash to the route if it doesn't have one
$route = "/" . $route;
}
// Template variables to be defined
$view = null;
$layout = null;
// Get the route row for the attempted route URI from the DB
$routeData = $Router->getRouteData($route);
if ($routeData === false){
// Route does not exist, get a 404 view
$routeData = $Router->getRouteData("/404");
if ($routeData === false){ // The 404 doesn't exist
http_response_code(404);
exit();
}else{
$viewFile = $documentRoot . $routeData['view'];
$layoutFile = $documentRoot . $routeData['layout'];
}
}else{
// Route exists
if (count($routeData['parameters'])){
// Merge parameters found (for regular expression routes) into the global $_GET array
$_GET = array_merge($_GET, $routeData['parameters']);
}
$viewFile = $documentRoot . $routeData['view'];
$layoutFile = $documentRoot . $routeData['layout'];
}
// Is there any custom data in the customData string?
$customData = $routeData['customData'];
extract($customData);
$view = $ViewEngine->renderView($viewFile);
$headContents = $view['head'];
$bodyContents = $view['body'];
include($layoutFile);
?>