-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.php
57 lines (39 loc) · 1.3 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
<?php
//for me , without this setting its not showing error // so will comment if not needed ,dont remove
/*ini_set('error_reporting', E_ALL);
ini_set('display_errors', 'On'); */
// include all controllers here
// require('./controller/Test.php');
require('./controller/User.php');
require('./controller/Test.php');
// call the controllers using
// domain(localhost)/app_name/index.php/Controller_name/function/args..../
function getArgumentStart($uri){
foreach ($uri as $key => $value){
if($value == 'index.php'){
if($key == count($uri) - 1 ) return -1;
return $key+1;
}
}
}
function main(){
$uri = parse_url($_SERVER['REQUEST_URI']);
//new php version have issue with split so using explode instead
$parameters = explode('/', $uri['path']);
// get query using $uri['query'] // TODO
$start = getArgumentStart($parameters);
if($start != -1){
$controller_name = $parameters[$start];
$function_name = $parameters[$start+1] . "_" . strtolower($_SERVER['REQUEST_METHOD']);
$start+=2;
$args = array();
for(;$start < count($parameters); $start++){
array_push($args, $parameters[$start]);
}
call_user_func_array(array(new $controller_name, $function_name), $args);
}else{
echo "404 not found";
}
}
main();
?>