-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
85 lines (73 loc) · 1.38 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
<?php
session_start();
define('DEVEL', true);
define('BASEPATH', '/booking/');
define('APPPATH', 'application/');
define('SYSPATH', 'system/');
define('ERRPATH', 'errors/');
// display errors in development
if (DEVEL)
{
error_reporting(E_ALL);
}
else
{
error_reporting(0);
}
require APPPATH.'config/config.php';
require SYSPATH.'model.php';
require SYSPATH.'controller.php';
include SYSPATH.'helpers.php';
// get the reques string passed to index.php
$request = $_SERVER['QUERY_STRING'];
// parse the page request and other parameters
$parsed = explode('/' , $request);
// the class is the first element
$class = array_shift($parsed);
if (empty($class))
{
$class = $default_controller;
}
//the method is the second element
if (!empty($parsed[0]))
{
$method = array_shift($parsed);
}
else
{
$method = 'index';
}
// modify class to fit naming convention
$class = ucfirst($class);
function __autoload($class_name) // autoload only controllers
{
$target = APPPATH . 'controllers/'.strtolower($class_name).'.php';
if (file_exists($target))
{
require $target;
}
}
// instantiate the appropriate class and display the page
if (class_exists($class)) // calls autoload here
{
$controller = new $class;
if(method_exists($controller, $method))
{
if (!empty($parsed))
{
$controller->$method($parsed);
}
else
{
$controller->$method();
}
}
else
{
show404();
}
}
else
{
show404();
}