function url_for($url, $absolute = false) { return mfRoute::generate($url, $absolute); }
/** * Compile the config route to regex match * * @param string $route * @return array regex */ private static function compile_route($route) { self::$compile_tokens = array(); // internel call back function for regex replacement if (!function_exists('_callback')) { function _callback($match) { mfRoute::$compile_tokens[] = $match[1]; //var_dump(Router::$compile_tokens);echo "<br />"; return "([a-zA-Z0-9\\-_%]+)"; } } $compile_tokens = array(); // Strip regex chars: / + ? . and _ - $reg_strip_parten = "/([\\/\\._-])/"; $reg_strip_repalce = '\\\\$1'; // replace with \(regex char) $route = preg_replace($reg_strip_parten, $reg_strip_repalce, $route); // FIXME more characters should allowed in match parten $route = preg_replace_callback("/:([a-zA-Z0-9\\-_%]+)/", '_callback', $route); $route = "/^{$route}\$/"; // add regex slash // echo $route . "<br />"; return array($route, self::$compile_tokens); }
public static function loadRoute() { $array = sfYaml::load(ROOT_DIR . DS . 'config' . DS . 'routing.yml'); $routes = array(); foreach ($array as $name => $route) { $routes[] = array($name, $route['url'], $route['params']); // formated route $routes[] = array("{$name}_formatted", $route['url'] . '.:format', $route['params']); } mfRoute::connect($routes); }