-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
87 lines (73 loc) · 1.92 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
define('DIR_CONTROLLER', 'app/controller/');
define('DIR_MODEL', 'app/model/');
define('DIR_VIEW', 'app/view/');
define('DIR_VIEWS', 'app/views/');
define('DIR_LIB', 'app/lib/');
define('DIR_MODULES', 'app/modules/');
include_once DIR_VIEW.'View.php';
include_once DIR_LIB.'Library.php';
include_once DIR_MODULES.'Module.php';
Library::load('route');
Library::load('router');
Library::load('exception404');
Library::load('session');
Library::load('html');
include_once 'app/bootstrap.php';
function __autoload($classname)
{
$temp = explode('_', $classname);
if(isset($temp[1]))
{
$classname = $temp[1];
}
if(strtolower($temp[0]) === 'controller')
{
if(file_exists(DIR_CONTROLLER.$classname.'.php'))
{
include_once DIR_CONTROLLER.$classname.'.php';
}
else
{
//throw new Exception('Nie znaleziono kontrolera: '.$classname);
throw new Exception404;
}
}
else if(strtolower($temp[0]) === 'model')
{
if(file_exists(DIR_MODEL.$classname.'.php'))
{
include_once DIR_MODEL.$classname.'.php';
}
else
{
throw new Exception('Nie znaleziono modelu: '.$classname);
}
}
else
{
throw new Exception('Nie znaleziono klasy: '.$classname);
}
}
try
{
// Router
$router = Router::instance($_SERVER['REQUEST_URI']);
$router->matchRoute();
// ----
$get_controller = basename($_GET['controller']);
$get_action = basename($_GET['action']);
$tmp = 'Controller_'.ucfirst(strtolower($get_controller));
$controller = new $tmp();
$controller->before();
$tmp = 'action_'.strtolower($get_action);
$controller->$tmp();
$controller->after();
}
catch(Exception $e)
{
echo $e->getMessage();
//echo '<br />Plik: '.$e->getFile();
//echo '<br />Linia: '.$e->getLine();
}
?>