/** * Constructor * * Runs the route mapping function. */ function MY_Router() { // {{{ Matchbox $this->_matchbox =& load_class('Matchbox'); // }}} parent::CI_Router(); }
function _validate_request($segments) { if (file_exists('pinet/controllers/' . $segments[0] . '.php')) { return $segments; } return parent::_validate_request($segments); }
function _set_request($segments = array()) { for ($i = 0; $i < count($segments) && $i < 2; $i++) { $segments[$i] = str_replace('-', '_', $segments[$i]); } parent::_set_request($segments); }
/** * set routes to lowercaser * @return string routes */ public function _parse_routes() { foreach ($this->uri->segments as &$segment) { $segment = strtolower($segment); } return parent::_parse_routes(); }
public function __construct() { if (isset($_SERVER['HTTP_APIVER'])) { $this->version = $_SERVER['HTTP_APIVER']; } parent::__construct(); }
/** * Constructor */ public function __construct() { $this->load_config(); $this->detect_method(); $fmt = $this->detect_format(); $this->detect_view($fmt); parent::CI_Router(); }
function _set_request($seg = array()) { // The str_replace() below goes through all our segments // and replaces the hyphens with underscores making it // possible to use hyphens in controllers, folder names and // function names parent::_set_request(str_replace('-', '_', $seg)); }
public function _validate_request($segments) { if (isset($segments[0])) { $segments[0] = $this->_repl($segments[0]); } if (isset($segments[1])) { $segments[1] = $this->_repl($segments[1]); } return parent::_validate_request($segments); }
function _set_routing() { parent::_set_routing(); // re-routed url if ($this->uri->rsegments != $this->segments) { if (count($this->uri->rsegments) > 0) { array_unshift($this->uri->rsegments, $this->_route['directory']); } } }
/** * Overrides base method to append _controller suffix to URI segment. * * @param array $segments * @return array $segments */ function _validate_request($segments) { // naming convention for all URI => controller classes if (isset($segments[0]) && !preg_match('/_controller$/', $segments[0])) { $segments[0] .= '_controller'; } // if controller doesn't exist, redirect to "home" controller $name = APPPATH . 'controllers/' . $segments[0]; if (!file_exists($name . EXT) && !is_dir($name)) { $segments = array('home_controller', '404'); } return parent::_validate_request($segments); }
function _parse_routes() { // Apply the current module's routing config if ($module = $this->uri->segment(0)) { foreach ($this->config->item('modules_locations') as $location) { if (is_file($file = $location . $module . '/config/routes.php')) { include $file; $route = (!isset($route) or !is_array($route)) ? array() : $route; $this->routes = array_merge($this->routes, $route); unset($route); } } } //使用默认 return parent::_parse_routes(); }
/** * {@inherit} */ protected function _validate_request($segments) { // here is the router hack, we have the method: locate // coming request uri is validated first by locating // the controller file, then use it if it exists, // use default behaviour otherwise. if ($located = $this->locate($segments)) { return $located; } if (isset($this->routes['404_override']) and $this->routes['404_override']) { $segments = explode('/', $this->routes['404_override']); if ($located = $this->locate($segments)) { return $located; } } return parent::_validate_request($segments); }
public function _validate_request($segments) { isset($segments[1]) or $segments[1] = NULL; /* locate the module controller */ list($module, $controller) = Router::locate($segments); /* not a module controller */ if ($controller === FALSE) { return parent::_validate_request($segments); } /* set the module path */ $path = $module ? MODOFFSET . $module . '/controllers/' : NULL; $this->set_directory($path); /* remove the directory segment */ if ($module != $controller and $module != FALSE) { $segments = array_slice($segments, 1); } return $segments; }
/** * Builds the object, sets up the router */ public function __construct() { parent::CI_Router(); }
function _set_request($seg = array()) { parent::_set_request(str_replace('-', '_', $seg)); }
public function set_class($class) { $suffix = $this->config->item('controller_suffix'); if (strpos($class, $suffix) === FALSE) { $class .= $suffix; } parent::set_class($class); }
public function __construct($routing = NULL) { $this->input =& load_class('Input', 'core'); parent::__construct($routing); }
function My_Router() { parent::CI_Router(); }
function _parse_routes() { $rest_routes = map_resources(); // we do this for performence if (empty($rest_routes) && count($this->routes) == 1) { $this->_set_request($this->uri->segments); return; } // also this... $uri = implode('/', $this->uri->segments); if (isset($this->routes[$uri])) { $this->_set_request(explode('/', $this->routes[$uri])); return; } // RESTful url matching... $request_method = $_SERVER['REQUEST_METHOD']; $routes = isset($rest_routes[$request_method]) && $rest_routes[$request_method] ? $rest_routes[$request_method] : array(); foreach ($routes as $pattern => $replace) { $pattern = str_replace(':id', '[^/]+', $pattern); // use this to match non-numeric id field $pattern = str_replace(':any', '.+', $pattern); $pattern = str_replace(':num', '[0-9]+', $pattern); $pattern = str_replace(':uuid', '[a-zA-Z0-9]{8}(-[a-zA-Z0-9]{4}){3}-[a-zA-Z0-9]{12}', $pattern); // Does the RegEx match? if (preg_match("#^{$pattern}\$#", $uri)) { // Do we have a back-reference? if (strpos($replace, '$') !== FALSE && strpos($pattern, '(') !== FALSE) { $replace = preg_replace("#^{$pattern}\$#", $replace, $uri); } // we are done $this->_set_request(explode('/', $replace)); return; } } // if non of the rules match, then go on... parent::_parse_routes(); }
function show_404() { parent::show_404(); }
/** * * @see Page * @see Page::setup() * @see CI_Router * @see CI_Router::_parse_routes() * @access public */ public function _parse_routes() { require_once APPPATH . '/libraries/Page.php'; Page::setup($this->uri->segments); parent::_parse_routes(); }
protected function _set_default_controller() { if ($bundle_path = $this->bundle->get_active_path()) { if (file_exists($bundle_path . 'config/routes.php')) { include $bundle_path . 'config/routes.php'; } isset($route['default_controller']) && ($this->default_controller = $route['default_controller']); unset($route['default_controller'], $route['translate_uri_dashes']); } return parent::_set_default_controller(); }
function _validate_request($segments) { // Regular non-modular requests are handled by stock CI code if ($this->_mb_module === FALSE) { return parent::_validate_request($segments); } // Now we need to find the relative path to the module $path = '../'; $path1 = explode('/', trim(str_replace("\\", "/", realpath(APPPATH)), '/')); $path2 = explode('/', trim($this->_mb_module . 'controllers', '/')); $size1 = count($path1); $size2 = count($path2); $diff = $size1 - $size2; for ($i = 0; $i < min($size1, $size2); $i++) { if ($path1[$i] !== $path2[$i]) { $path = '../' . $path . $path2[$i] . '/'; } } $path = ($diff > 0 ? str_repeat('../', $diff) : '') . $path . implode('/', array_slice($path2, $size1)); $this->set_directory($path); $directory = $this->_mb_module . 'controllers/'; // Does the controller exist in module controller root? if (file_exists($directory . $segments[0] . EXT)) { return $segments; } // At this point, the controller can only be in a sub-directory if (!is_dir($directory . $segments[0])) { show_404($directory . $segments[0]); } $this->set_directory($this->fetch_directory() . $segments[0]); $directory .= $segments[0] . '/'; $segments = array_slice($segments, 1); if (count($segments) > 0) { if (!file_exists($directory . $segments[0] . EXT)) { show_404($directory . $segments[0]); } } else { $this->set_class($this->_mb_default_controller); $this->set_method('index'); if (!file_exists($directory . $this->_mb_default_controller . EXT)) { $this->directory2 = ''; return array(); } } return $segments; }
/** * Constructor * * Runs the route mapping function. */ public function __construct() { parent::__construct(); }
public function set_class($class) { $class = $class . $this->config->item('controller_suffix'); parent::set_class($class); }
/** * Set default controller * * First we check in normal APPPATH/controller's location, * then in Modules named after the default_controller * @author hArpanet - based on system/core/Router.php * * @return void */ protected function _set_default_controller() { // controller in APPPATH/controllers takes priority over module with same name parent::_set_default_controller(); // see if parent found a controller $class = $this->fetch_class(); if (empty($class)) { // no 'normal' controller found, // get the class/method from the default_controller route if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) { $method = 'index'; } // try to locate default controller in modules if ($located = $this->locate(array($class, $class, $method))) { log_message('debug', 'No URI present. Default module controller set.'); } } // Nothing found - this will trigger 404 later }
function MY_Router() { parent::__construct(); }
function __construct() { // Call the Model constructor parent::__construct(); }
/** * Set default controller * * @return void */ protected function _set_default_controller() { parent::_set_default_controller(); $this->active_route = 'default_controller'; }
function __construct() { parent::__construct(); log_message('debug', 'Plain_Router Class Initialized'); }