<?php
error_reporting(0);
$default = 'controller/welcome.php';
// include header
if (file_exists('view/header.php')) {
include('view/header.php');
}
// include navigation
if (file_exists('view/navigation.php')) {
include('view/navigation.php');
}
// index.php == 9 characters
$location = substr($_SERVER['SCRIPT_NAME'], 0, -9);
// Entry point for application
$location_size = strlen($location);
// Get full URI
$uri = $_SERVER['REQUEST_URI'];
$route = substr($uri,$location_size);
// Turn Arguments into an array
$reqs = explode('/', $route);
/* Get number of arguments
1 = Controller
2 = Function (else index)
3+ = Arguments
*/
$num_args = sizeof($reqs);
$controller = 'controller/' . $reqs[0] . '.php';
if ($location == $uri) {
/* on index page*/
include($default);
} else {
// Load Controller (classes)
if (file_exists($controller)) {
include($controller);
} else {
include('notfound.php');
}
$controller_name = $reqs[0];
// Instantiate Controller
$$controller_name = new $controller_name();
if ($num_args == 1) {
$$controller_name->index();
} else if ($num_args == 2) {
$function_name = $reqs[1];
$$controller_name->$function_name();
} else {
$function_name = $reqs[1];
// size of arguments array
$arguments = $num_args - 2;
// Put arguments into temporary array
$arg_array = array();
for ($i=2;$i<$num_args;$i++) {
array_push($arg_array, $reqs[$i]);
}
if ($arguments == 1) {
$$controller_name->$function_name($arg_array[0]);
} else if ($arguments == 2) {
$$controller_name->$function_name($arg_array[0], $arg_array[1]);
}
}
}
if (file_exists('view/footer.php')) {
include('view/footer.php');
}
?>