-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
60 lines (47 loc) · 1.66 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
<?
include('base/controllers.php');
if (file_exists('settings.php'))
include('settings.php');
$DIRNAME = array_pop(explode('/', dirname(__FILE__)));
$VIEWPATH = 'views/';
if(file_exists('controllers.php'))
include('controllers.php');
if (strpos($_SERVER['REQUEST_URI'], '?'))
list($path, $args) = explode(
'?',
$_SERVER['REQUEST_URI'],
2 );
else
list($path, $args) = array($_SERVER['REQUEST_URI'], null);
if ($args){
$args = explode('&', $args);
$params = array();
foreach ($args as $arg){
list($k, $v) = explode('=', $arg);
$params[ $k ] = $v;
}
}
else
$params = '';
$path = array_filter( # remove empty elements
explode( '/', # split the url path into an array
str_replace( # remove the framework directory from the path
$DIRNAME, # the directory name
null, # replace with nothing
$path # the url
) ) );
$controller = array_shift($path); # get the first part of the url (controller class name)
if (!$controller){ # no path?
$controller = 'home';
if (!class_exists($controller)) # try for the Index class
$controller = 'DefaultIndex'; # otherwise default to base/controllers.php's DefaultIndex class
}
if (!class_exists($controller)) # catch paths without controllers
echo sprintf(
"There is no controller written to
handle the path <strong>/%s</strong>.",
strtolower($controller) );
else{
$object = new $controller($path, $params); # instantiate controller
}
?>