public static function matchRoute($uri) { $matched = false; foreach (self::$_routes as $key => $value) { if ($uri == $key) { $matched = true; self::$_module = $value['module']; self::$_controller = $value['controller']; self::$_action = $value['action']; } } if ($matched !== true) { header('HTTP/1.0 404 Not Found'); exit("<h1>404 Not Found</h1>The page that you have requested could not be found."); } }
private static function _init() { $url = preg_replace("/[#\\?].*\$/", '', $_SERVER['REQUEST_URI']); $_paths = explode('/', $url); $paths = array(); foreach ($_paths as $path) { if ($path !== '' && $path != '.' && $path != '..') { $paths[] = $path; } } if (!empty($paths[0]) && in_array($paths[0], self::$_modules)) { self::$_module = array_shift($paths); } else { self::$_module = null; } if (count($paths) == 0) { $paths[] = 'index'; } if (count($paths) == 1) { $paths[] = 'default'; } self::$_controller = !empty($paths[0]) ? array_shift($paths) : 'index'; self::$_action = !empty($paths[0]) ? array_shift($paths) : 'default'; if (count($paths) > 0) { foreach ($paths as $path) { self::$_params[] = rawurldecode($path); } } }