Example #1
0
}
// Get all params as an array.
$params = explode("/", $url_decoded_request_array['path']);
// Remove special chars.
foreach ($params as &$param) {
    $param = preg_replace("/\\W/", "", $param);
}
// Get the controller.
array_shift($params);
if (empty($params[0])) {
    $params = array('main');
}
// Check if controller exist
if (!file_exists('controllers/' . $params[0] . '.php')) {
    $controller = new Controller();
    $controller->no_such_controller();
    unset($controller);
    exit;
}
// Include the controller.
include './controllers/' . $params[0] . '.php';
// Create controller instance.
$controller_name = strtolower($params[0]);
$controller = new $controller_name();
try {
    // Set request type.
    $controller->set_request_type($set_request_type);
    // Get the controller action.
    array_shift($params);
    if (!isset($params[0])) {
        $params[0] = 'init';