public function locate($segments)
{
$this->located = 0;
$ext = $this->config->item('controller_suffix') . EXT;
/* use module route if available */
if (isset($segments[0]) && ($routes = Modules::parse_routes($segments[0], implode('/', $segments)))) {
$segments = $routes;
}
/* get the segments array elements */
list($module, $directory, $controller) = array_pad($segments, 3, NULL);
/* check modules */
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) {
/* module sub-directory exists? */
if (is_dir($source . $directory . '/')) {
$source .= $directory . '/';
$this->directory .= $directory . '/';
/* module sub-directory controller exists? */
if ($controller) {
if (is_file($source . ucfirst($controller) . $ext)) {
$this->located = 3;
return array_slice($segments, 2);
} else {
$this->located = -1;
}
}
} else {
if (is_file($source . ucfirst($directory) . $ext)) {
$this->located = 2;
return array_slice($segments, 1);
} else {
$this->located = -1;
}
}
}
/* module controller exists? */
if (is_file($source . ucfirst($module) . $ext)) {
$this->located = 1;
return $segments;
}
}
}
if (!empty($this->directory)) {
return;
}
/* application sub-directory controller exists? */
if ($directory) {
if (is_file(APPPATH . 'controllers/' . $module . '/' . ucfirst($directory) . $ext)) {
$this->directory = $module . '/';
return array_slice($segments, 1);
}
/* application sub-sub-directory controller exists? */
if ($controller) {
if (is_file(APPPATH . 'controllers/' . $module . '/' . $directory . '/' . ucfirst($controller) . $ext)) {
$this->directory = $module . '/' . $directory . '/';
return array_slice($segments, 2);
}
}
}
/* application controllers sub-directory exists? */
if (is_dir(APPPATH . 'controllers/' . $module . '/')) {
$this->directory = $module . '/';
return array_slice($segments, 1);
}
/* application controller exists? */
if (is_file(APPPATH . 'controllers/' . ucfirst($module) . $ext)) {
return $segments;
}
$this->located = -1;
}