-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
80 lines (65 loc) · 1.72 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
<?php
session_start();
// define configurations
define('ROOT', dirname(__FILE__));
define('DS', DIRECTORY_SEPARATOR);
// now require file
require_once "config.php";
require_once "library/database.class.php";
require_once "library/model.class.php";
require_once "library/eloquent.class.php";
require_once "library/view.class.php";
require_once "library/controller.class.php";
// autoload function
function __autoload($className)
{
$fileName = str_replace("\\", DS, $className) . '.php';
if(!file_exists($fileName))
{
return false;
}
include $fileName;
}
// membuat MVC
$page = (isset($_GET['page']) && $_GET['page']) ? $_GET['page'] : 'Home';
$controller = ROOT . DS . 'modules' . DS . 'controllers' . DS . $page . 'Controller.php';
if(file_exists($controller))
{
// membuat object controller
require_once $controller;
$exploded = explode('/', $page);
$controllerName = ucfirst(end($exploded)) . 'Controller';
$obj = new $controllerName();
$action = (isset($_GET['action']) && $_GET['action']) ? $_GET['action'] : 'index';
if(method_exists($obj, $action))
{
$arguments = array();
// Menyesuaikan argumen function dengan nama kunci dari index $_GET
$reflectMethod = new ReflectionMethod($obj, $action);
foreach($reflectMethod->getParameters() as $arg)
{
if($_GET[$arg->name])
{
array_push($arguments, $_GET[$arg->name]);
}
else if($arg->isDefaultValueAvailable())
{
array_push($arguments, $arg->getDefaultValue());
}
else
{
array_push($arguments, null);
}
}
call_user_func_array(array($obj, $action), $arguments);
}
else
{
die('Action Not Found !');
}
}
else
{
die('Controller Not Found !');
}
?>