Attempts validate the URI request and determine the controller path.
protected _validate_request ( array $segments ) : mixed | ||
$segments | array | URI segments |
return | mixed | URI segments |
function _validate_request($segments) { if (file_exists('pinet/controllers/' . $segments[0] . '.php')) { return $segments; } return parent::_validate_request($segments); }
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); }
/** * 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); }
/** * {@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; }
/** * {inheritdoc} */ protected function _validate_request($segments) { if (count($segments) == 0) { return $segments; } // Locate the controller with modules support if ($located = $this->locate($segments)) { return $located; } // Is there a 404 override? if (!empty($this->routes['404_override'])) { $segments = explode('/', $this->routes['404_override']); if ($located = $this->locate($segments)) { return $located; } } // Nothing else to do at this point but show a 404 return parent::_validate_request($segments); }
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; }
/** Locate the controller **/ public function locate($segments) { $this->module = ''; $this->directory = ''; /* use module route if available */ if (isset($segments[0]) and $routes = Modules::parse_routes($segments[0], implode('/', $segments))) { $segments = $routes; } /* get the segments array elements */ list($module, $directory, $controller) = array_pad($segments, 3, NULL); foreach (Modules::$locations as $location => $offset) { /* module exists? */ if (is_dir($source = $location . $module . '/controllers/')) { $this->module = $module; $this->directory = $offset . $module . '/controllers/'; /* module sub-controller exists? */ if ($directory and is_file($source . $directory . EXT)) { return array_slice($segments, 1); } /* module sub-directory exists? */ if ($directory and is_dir($module_subdir = $source . $directory . '/')) { $this->directory .= $directory . '/'; /* module sub-directory sub-controller exists? */ if ($controller and is_file($module_subdir . $controller . EXT)) { return array_slice($segments, 2); } /* module sub-directory controller exists? */ if (is_file($module_subdir . $directory . EXT)) { return array_slice($segments, 1); } } /* module controller exists? */ if (is_file($source . $module . EXT)) { return $segments; } } } /* not a module controller */ return parent::_validate_request($segments); }