/
index.php
72 lines (55 loc) · 1.53 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
65
66
67
68
69
70
71
72
<?php
session_start();
include("controllers/Controller.php");
include("models/Cities.php");
include("models/Types.php");
include("models/Users.php");
include("models/Employees.php");
include("models/Accommodations.php");
include("models/Bookings.php");
include("models/Categories.php");
include("models/Reviews.php");
include("models/Searches.php");
include("libs/DB.php");
include("libs/Errors.php");
$controller = setVariable("controller", "Public");
$action = setVariable("action", "main");
function setVariable($name, $default){
if (isset($_POST[$name]))
{
return $_POST[$name];
}
if (isset($_GET[$name]))
{
return $_GET[$name];
}
return $default;
}
$controllerName = ucfirst($controller)."Controller";
$controllerFile = "controllers/".$controllerName.".php";
if(file_exists($controllerFile))
{
include($controllerFile);
// create an instance of the controller
$theController = new $controllerName();
// if there is a function inside the controller, called pretrip
// then call that function, BEFORE calling the main action we requested
if(method_exists($theController, "pretrip"))
{
$theController->pretrip(); // pretrip is a way of doing something before the main action (also known as a mixin)
}
// now call the main action the user requested
if(method_exists($theController, $action))
{
$theController->$action();
if ($theController->bLastViewRun)
{
$theController->output();
}
} else {
Errors::missingMethodError($controllerName, $action);
}
} else {
Errors::missingControllerError($controllerName);
}
?>