-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
executable file
·64 lines (54 loc) · 1.58 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
63
64
<?php
define('PROJECT_ROOT', dirname(__FILE__));
define('PR', PROJECT_ROOT);
/**
* Routing
*/
// Fetch the route values
$requestUri = $_SERVER['REQUEST_URI'];
if (count(explode('/', $requestUri)) > 2) {
list($zero, $requestPath['controller'], $requestPath['action']) = explode('/', $requestUri);
}
// Fall back to default values if none where provided
if (empty($requestPath['controller'])) {
$requestPath['controller'] = 'home';
}
if (empty($requestPath['action'])) {
$requestPath['action'] = 'index';
}
/**
* Controller
*/
// Decide which controller to use
$controllerName = $requestPath['controller'];
$ucfirstControllerName = ucfirst($controllerName);
$methodName = $requestPath['action'];
include_once("controllers/$controllerName.class.php");
$controller = new $ucfirstControllerName();
$controller->$methodName();
// Merge the provided viewVars
require_once(PR . '/handlers/responseHandler.class.php');
$responseHandler = ResponseHandler::init();
$responseHandler->setVars(
array(
'pageTitle' => 'Braille converter',
'pageSubject' => $ucfirstControllerName,
)
);
// Make the viewVars available for the upcoming view(s)
extract($responseHandler->getVars());
/**
* View
*/
define('RESOURCES_BASE', '/resources/');
$base = array(
'css' => RESOURCES_BASE . 'css/',
'javascript' => RESOURCES_BASE . 'js/'
);
// Fetch messages if provided
$messagesArray = $responseHandler->messages;
// Convert the message to HTML
include_once(PR."/views/elements/messages.php");
// Load the view
include_once(PR."/views/$controllerName/$methodName.php");
echo $output;