/** * autoDispatch by Volter9 * Ability to call controllers in their controller/model/param way */ public static function autoDispatch() { $uri = parse_url($_SERVER['QUERY_STRING'], PHP_URL_PATH); $uri = trim($uri, ' /'); $uri = ($amp = strpos($uri, '&')) !== false ? substr($uri, 0, $amp) : $uri; $parts = explode('/', $uri); $controller = array_shift($parts); $controller = $controller ? $controller : DEFAULT_CONTROLLER; $method = array_shift($parts); $method = $method ? $method : DEFAULT_METHOD; $args = !empty($parts) ? $parts : array(); // Check for file if (!file_exists("app/Controllers/" . ucfirst($controller) . ".php")) { $myroute = Page::cmsRoute(); $customRoute = $parts[0]; if ($myroute > 0) { self::get($customRoute, '\\Controllers\\Page@index'); self::get($customRoute . '/(:any)', '\\Controllers\\Page@index'); self::get($customRoute . '/(:any)/(:any)', '\\Controllers\\Page@index'); self::dispatch(); } else { return false; } return true; } $controller = ucwords($controller); $controller = "\\Controllers\\{$controller}"; $c = new $controller(); if (method_exists($c, $method)) { $c->{$method}($args); //found method so stop return true; } return false; }