-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
70 lines (59 loc) · 2.08 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
<?php
define("APP_FOLDER", "php/app");
define("APP_URL", "http://".$_SERVER['SERVER_NAME'].":8888/".APP_FOLDER."/");
define("APP_URL_CSS", APP_URL."public/css/");
define("APP_URL_IMG", APP_URL."public/img/");
define("APP_URL_JS", APP_URL."public/js/");
define("DS", DIRECTORY_SEPARATOR);
define("ROOT", realpath(dirname(__FILE__)).DS);
define("APP_PATH", ROOT."application".DS);
define("LIB_PATH", ROOT."libs".DS);
require_once(APP_PATH."config.php");
require_once(LIB_PATH."PDO.php");
require_once(LIB_PATH."Authorization.php");
require_once(LIB_PATH."Password.php");
require_once(LIB_PATH."Validations.php");
require_once(APP_PATH."request.php");
require_once(APP_PATH."bootstrap.php");
require_once(APP_PATH."controller.php");
require_once(APP_PATH."model.php");
require_once(APP_PATH."view.php");
if (isset($_GET['url'])) {
$url = filter_input(INPUT_GET, 'url', FILTER_SANITIZE_URL);
$url = explode("/", $url);
$url = array_filter($url);
$controller = array_shift($url);
$action = array_shift($url);
$args = $url;
}
if (!isset($controller)) $controller = "pages";
if (!isset($action)) $action = "index";
if (empty($args)) $args = array();
$path = ROOT."controllers".DS.$controller."Controller.php";
$view = ROOT."views".DS.$controller.DS.$action.".php";
$header = ROOT."views".DS."layouts".DS."default".DS."header.php";
$footer = ROOT."views".DS."layouts".DS."default".DS."footer.php";
if ($action == "login") {
$header = ROOT."views".DS."layouts".DS."login".DS."header.php";
$footer = ROOT."views".DS."layouts".DS."login".DS."footer.php";
} else {
Authorization::logged();
}
if (file_exists($path)) {
include_once($path);
$ob = new $controller();
if (method_exists($ob, $action)) {
$ob->$action($args);
if (file_exists($view)) {
include_once($header);
include_once($view);
include_once($footer);
} else {
echo "La vista para la acción $action no existe";
}
} else {
echo "La acción $action no existe";
}
} else {
echo "El controlador $controller no existe";
}