/** * 获得动作参数 */ public static function getParams() { //此条URL规则作废URL http://sk.com/sk80/index.php?job=archive&action=archive&arg=alias_google-out-china&page=1 //URL http://sk.com/sk80/index.php?job=archive&action=archive&alias=google-out-china&page=1 //处理有分页的情况 $parmas = array(); $params = self::$request; if (array_key_exists('job', $params)) { unset($params['job']); } if (array_key_exists('action', $params)) { unset($params['action']); } return self::$params = $params; }
public static function dispatch($requested_url = null, $default = null) { Flash::init(); // If no url passed, we will get the first key from the _GET array // that way, index.php?/controller/action/var1&email=example@example.com // requested_url will be equal to: /controller/action/var1 if ($requested_url === null) { $pos = strpos($_SERVER['QUERY_STRING'], '&'); if ($pos !== false) { $requested_url = substr($_SERVER['QUERY_STRING'], 0, $pos); } else { $requested_url = $_SERVER['QUERY_STRING']; } } // If no URL is requested (due to someone accessing admin section for the first time) // AND $default is setAllow for a default tab if ($requested_url == null && $default != null) { $requested_url = $default; } // Requested url MUST start with a slash (for route convention) if (strpos($requested_url, '/') !== 0) { $requested_url = '/' . $requested_url; } self::$requested_url = $requested_url; // This is only trace for debugging self::$status['requested_url'] = $requested_url; // Make the first split of the current requested_url self::$params = self::splitUrl($requested_url); // Do we even have any custom routing to deal with? if (count(self::$routes) === 0) { return self::executeAction(self::getController(), self::getAction(), self::getParams()); } // Is there a literal match? If so we're done if (isset(self::$routes[$requested_url])) { self::$params = self::splitUrl(self::$routes[$requested_url]); return self::executeAction(self::getController(), self::getAction(), self::getParams()); } // Loop through the route array looking for wildcards foreach (self::$routes as $route => $uri) { // Convert wildcards to regex if (strpos($route, ':') !== false) { $route = str_replace(':any', '(.+)', str_replace(':num', '([0-9]+)', $route)); } // Does the regex match? if (preg_match('#^' . $route . '$#', $requested_url)) { // Do we have a back-reference? if (strpos($uri, '$') !== false && strpos($route, '(') !== false) { $uri = preg_replace('#^' . $route . '$#', $uri, $requested_url); } self::$params = self::splitUrl($uri); // We found it, so we can break the loop now! break; } } return self::executeAction(self::getController(), self::getAction(), self::getParams()); }