-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
43 lines (28 loc) · 848 Bytes
/
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
<?php
define("DEFAULT_CONTROLLER", "users");
define("DEFAULT_ACTION", "inicio");
function run() {
try {
if (!isset($_GET["controller"])) {
$_GET["controller"] = DEFAULT_CONTROLLER;
}
if (!isset($_GET["action"])) {
$_GET["action"] = DEFAULT_ACTION;
}
$controller = loadController($_GET["controller"]);
$actionName = $_GET["action"];
$controller->$actionName();
} catch(Exception $ex) {
die("An exception occured!!!!!".$ex->getMessage());
}
}
function loadController($controllerName) {
$controllerClassName = getControllerClassName($controllerName);
require_once(__DIR__."/controller/".$controllerClassName.".php");
return new $controllerClassName();
}
function getControllerClassName($controllerName) {
return strToUpper(substr($controllerName, 0, 1)).substr($controllerName, 1)."Controller";
}
run();
?>