本文整理汇总了PHP中Modules::parse_routes方法的典型用法代码示例。如果您正苦于以下问题:PHP Modules::parse_routes方法的具体用法?PHP Modules::parse_routes怎么用?PHP Modules::parse_routes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Modules
的用法示例。
在下文中一共展示了Modules::parse_routes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: locate
/** Locate the controller **/
public function locate($segments)
{
$this->module = '';
$this->directory = '';
$ext = $this->config->item('controller_suffix') . EXT;
/* 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);
//print_r(Modules::$locations);die;
/* check modules */
foreach (Modules::$locations as $location => $offset) {
if (!is_dir($location . $module)) {
list($client, $module, $directory, $controller) = array_pad($segments, 4, NULL);
}
/* 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($source . $directory . '/')) {
$source = $source . $directory . '/';
$this->directory .= $directory . '/';
/* module sub-directory controller exists? */
if (is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory sub-controller exists? */
if ($controller and is_file($source . $controller . $ext)) {
return array_slice($segments, 2);
}
}
/* module controller exists? */
if (is_file($source . $module . $ext)) {
return $segments;
}
}
}
/* application controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
return $segments;
}
/* application sub-directory controller exists? */
if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
$this->directory = $module . '/';
return array_slice($segments, 1);
}
/* application sub-directory default controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
$this->directory = $module . '/';
return array($this->default_controller);
}
}
示例2: locate
/** Locate the controller **/
public function locate($segments)
{
$this->module = '';
$this->directory = '';
$ext = $this->config->item('controller_suffix') . '.php';
/* 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 && is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory exists? */
if ($directory && is_dir($source . $directory . '/')) {
$source = $source . $directory . '/';
$this->directory .= $directory . '/';
/* module sub-directory controller exists? */
if (is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory sub-controller exists? */
if ($controller && is_file($source . $controller . $ext)) {
return array_slice($segments, 2);
}
}
/* module controller exists? */
if (is_file($source . $module . $ext)) {
return $segments;
}
}
}
foreach (array(APPPATH, BFPATH) as $searchPath) {
/* application controller exists? */
if (is_file($searchPath . 'controllers/' . $module . $ext)) {
return $segments;
}
/* application sub-directory controller exists? */
if ($directory && is_file($searchPath . 'controllers/' . $module . '/' . $directory . $ext)) {
$this->directory = $module . '/';
return array_slice($segments, 1);
}
/* application sub-directory default controller exists? */
if (is_file($searchPath . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
$this->directory = $module . '/';
return array($this->default_controller);
}
}
}
示例3: locate
/** Locate the controller **/
public function locate($segments)
{
$this->module = '';
$this->directory = '';
$ext = $this->config->item('controller_suffix') . EXT;
/* 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);
/* check modules */
foreach (Modules::$locations as $location => $offset) {
/* module exists? */
if (is_dir($source = $offset . '/' . $module . '/controllers/')) {
$this->module = $module;
$this->directory = '../../' . $offset . '/' . $module . '/controllers/';
// custom disini ... pakai dua kali segment '../' karena di 'core/CodeIgniter.php' langsung di fix dari 'applicaton/controller'
/* 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($source . $directory . '/')) {
$source = $source . $directory . '/';
$this->directory .= $directory . '/';
/* module sub-directory controller exists? */
if (is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory sub-controller exists? */
if ($controller and is_file($source . $controller . $ext)) {
return array_slice($segments, 2);
}
}
/* module controller exists? */
if (is_file($source . $module . $ext)) {
return $segments;
}
}
}
/* application controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
return $segments;
}
/* application sub-directory controller exists? */
if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
$this->directory = $module . '/';
return array_slice($segments, 1);
}
/* application sub-directory default controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
$this->directory = $module . '/';
return array($this->default_controller);
}
}
示例4: locate
/** 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 controller exists? */
if (is_file($module_subdir . $directory . EXT)) {
return array_slice($segments, 1);
}
/* module sub-directory sub-controller exists? */
if ($controller and is_file($module_subdir . $controller . EXT)) {
return array_slice($segments, 2);
}
}
/* module controller exists? */
if (is_file($source . $module . EXT)) {
return $segments;
}
}
}
/* application controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . EXT)) {
return $segments;
}
/* application sub-directory controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . '/' . $directory . EXT)) {
$this->directory = $module . '/';
return array_slice($segments, 1);
}
}
示例5: locate
/** Locate the controller **/
public function locate($segments)
{
$this->module = '';
$this->directory = '';
$ext = $this->config->item('controller_suffix') . EXT;
/* use module route if available */
if (isset($segments[0]) and $routes = Modules::parse_routes($segments[0], implode('/', $segments))) {
$segments = $routes;
}
if (isset($segments[0]) && $segments[0] == 'admin') {
$lang = 'en';
} else {
if (isset($segments[0]) && $segments[0] == 'tv') {
$lang = 'en';
} else {
if (count($segments) >= 2) {
$lang = $segments[0];
array_shift($segments);
} else {
$res = explode('/', $this->routes['default_controller']);
$lang = $res[0];
$segments = array($res[1]);
}
}
}
// echo $lang;
// print_r($segments);die;
/* 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 and is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory exists? */
if ($directory and is_dir($source . $directory . '/')) {
$source = $source . $directory . '/';
$this->directory .= $directory . '/';
/* module sub-directory controller exists? */
if (is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory sub-controller exists? */
if ($controller and is_file($source . $controller . $ext)) {
return array_slice($segments, 2);
}
}
/* module controller exists? */
if (is_file($source . $module . $ext)) {
return $segments;
}
}
}
/* application controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
return $segments;
}
/* application sub-directory controller exists? */
if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
$this->directory = $module . '/';
return array_slice($segments, 1);
}
/* application sub-directory default controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
$this->directory = $module . '/';
return array($this->default_controller);
}
}
示例6: locate
/** Locate the controller **/
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;
}
示例7: locate
/** Locate the controller **/
public function locate($segments)
{
$this->module = '';
$this->directory = '';
$ext = $this->config->item('controller_suffix') . EXT;
/* use module route if available */
/* but only if we are not in back-end admin */
if (isset($segments[0]) and (isset($segments[1]) and $segments[1] != 'admin') 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) {
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;
}
}
// End
}
// End foreach()
/* application controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
return $segments;
}
/* application sub-directory controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
$this->directory = $module . '/';
return array_slice($segments, 1);
}
}
示例8: locate
/** Locate the controller **/
public function locate($segments)
{
$this->module = '';
$this->directory = '';
$this->location = '';
$ext = $this->config->item('controller_suffix') . EXT;
$routed = implode("/", $segments);
/* use module route if available and use exact module location if exists */
if (isset($segments[0]) && $this->module_map($segments[0]) and list($routes) = Modules::parse_routes($segments[0], $routed, $this->module_map($segments[0]))) {
$segments = $routes;
} elseif (isset($segments[0])) {
//log_message('debug', "Scanning for first match in all modules' routing files with the URI segment: " . $routed);
//Get all of the module names and locations
$directories = $this->module_map();
foreach ($directories as $module => $locations) {
if (list($routes) = Modules::parse_routes($module, $routed, array($module => $locations))) {
$segments = $routes;
//Since a route is found, no need to keep looking, break out of loop
break;
}
}
}
// Let's see where the request originated ie, from a module or router, (is there a better way?)
// If it comes from a router that assumes it is being loaded via a public website address, if it comes from
// a module then that means it was called from somewhere internally. Tests indicate this is almost a free
// task, benchmarks show 0.0000 seconds to complete, so not even traceable.
$trace = debug_backtrace();
$module_source = isset($trace[1]['class']) && $trace[1]['class'] == 'Modules' && isset($trace[1]['function']) && $trace[1]['function'] == 'load';
// Should all modules be unaccessable unless a route explicitly matches?
if ($this->remove_default_routes && !$module_source && empty($routes) && !$this->_validate_route($routed)) {
return;
}
// Let's make sure all segments are lower case. It is possible in routing files that uppercase letters are
// used. This ensures everything gets translated to lowercase. The main reason for doing this is that on
// Windows machines since files will match any case, it may work there, but on Linux machines it must match
// the exact case. This could cause differences between development machines and production machines which
// would allow a route to work fine on Windows, but not on Linux, and may be hard to trace the cause. By
// adding this you should always ensure all controllers are in lowercase.
$segments = array_map('strtolower', $segments);
/* get the segments array elements */
list($module, $directory, $controller) = array_pad($segments, 3, NULL);
/* check modules */
$directories = $this->module_map($module);
foreach ($directories as $module => $locations) {
foreach ($locations as $location) {
$offset = Modules::$locations[$location];
/* module exists? */
if (is_dir($source = $location . $module . '/controllers/')) {
$this->module = $module;
$this->directory = $offset . $module . '/controllers/';
$this->location = $location;
/* 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($source . $directory . '/')) {
$source = $source . $directory . '/';
$this->directory .= $directory . '/';
/* module sub-directory controller exists? */
if (is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory sub-controller exists? */
if ($controller and is_file($source . $controller . $ext)) {
return array_slice($segments, 2);
}
}
/* module controller exists? */
if (is_file($source . $module . $ext)) {
return $segments;
}
}
}
}
/* application controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
return $segments;
}
/* application sub-directory controller exists? */
if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
$this->directory = $module . '/';
return array_slice($segments, 1);
}
/* application sub-directory default controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
$this->directory = $module . '/';
return array($this->default_controller);
}
}
示例9: locate
public function locate($segments, $router_initialization = true)
{
//
// Resolving the language.
if ($router_initialization) {
if (!empty($segments) && $this->config->valid_language_uri_segment($segments[0])) {
$language = $this->config->language_by_uri_segment($segments[0]);
array_shift($segments);
$this->config->set_current_language($language);
if (empty($segments)) {
$segments = array($this->default_controller, 'index');
}
}
}
// Processing slugs, if there are any.
if ($router_initialization) {
$segments = $this->remap($segments, $router_initialization);
}
$this->module = '';
$this->directory = '';
// 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($segment0, $segment1, $segment2) = array_pad($segments, 3, NULL);
$segment0 = str_replace('-', '_', $segment0);
$segment1 = str_replace('-', '_', $segment1);
$segment2 = str_replace('-', '_', $segment2);
// Check modules.
foreach (Modules::$locations as $location => $offset) {
// Module exists?
if (is_dir($source = $location . $segment0 . '/controllers/')) {
$is_module_default_controller = false;
$is_module_controller = false;
$is_module_directory = false;
$is_module_directory_default_controller = false;
$is_module_directory_controller = false;
$subdirectory = '';
$this->module = $segment0;
$this->directory = $offset . $segment0 . '/controllers/';
// module/controller
if ($segment1 && ($this->is_controller($source . ucfirst($segment1)) || $this->is_controller($source . $segment1))) {
$is_module_controller = true;
}
// module/directory
if ($segment1 && is_dir($source . $segment1 . '/')) {
$is_module_directory = true;
$source = $source . $segment1 . '/';
$subdirectory = $this->directory . $segment1 . '/';
// module/directory (deault_controller = directory)
if ($this->is_controller($source . ucfirst($segment1)) || $this->is_controller($source . $segment1)) {
$is_module_directory_default_controller = true;
}
// module/directory/controller
if ($segment2 && ($this->is_controller($source . ucfirst($segment2)) || $this->is_controller($source . $segment2))) {
$is_module_directory_controller = true;
}
}
// module (deault_controller = module)
if ($this->is_controller($source . ucfirst($segment0)) || $this->is_controller($source . $segment0)) {
$is_module_default_controller = true;
}
/*
// This is the original logic.
if ($is_module_controller) {
return array_slice($segments, 1);
} elseif ($is_module_directory) {
$this->directory = $subdirectory;
if ($is_module_directory_default_controller) {
return array_slice($segments, 1);
} elseif ($is_module_directory_controller) {
return array_slice($segments, 2);
}
} elseif ($is_module_default_controller) {
return $segments;
}
*/
// This is the modified logic, Ivan Tcholakov, 16-JUN-2012.
$result = false;
if ($is_module_controller && $is_module_directory && ($is_module_directory_default_controller || $is_module_directory_controller)) {
$this->directory = $subdirectory;
if ($is_module_directory_default_controller) {
$result = array_slice($segments, 1);
if ($router_initialization) {
$this->rdir = $segment0 . '/';
}
} elseif ($is_module_directory_controller) {
$result = array_slice($segments, 2);
if ($router_initialization) {
$this->rdir = $segment0 . '/' . $segment1 . '/';
}
}
} elseif ($is_module_controller) {
$result = array_slice($segments, 1);
if ($router_initialization) {
$this->rdir = $segment0 . '/';
}
} elseif ($is_module_directory) {
$this->directory = $subdirectory;
//.........这里部分代码省略.........
示例10: locate
/** Locate the controller **/
public function locate($segments)
{
$this->module = '';
$this->directory = '';
// 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($segment0, $segment1, $segment2) = array_pad($segments, 3, NULL);
$segment0 = str_replace('-', '_', $segment0);
$segment1 = str_replace('-', '_', $segment1);
$segment2 = str_replace('-', '_', $segment2);
// Check modules.
foreach (Modules::$locations as $location => $offset) {
// Module exists?
if (is_dir($source = $location . $segment0 . '/controllers/')) {
$is_module_default_controller = false;
$is_module_controller = false;
$is_module_directory = false;
$is_module_directory_default_controller = false;
$is_module_directory_controller = false;
$subdirectory = '';
$this->module = $segment0;
$this->directory = $offset . $segment0 . '/controllers/';
// module/controller
if ($segment1 && ($this->is_controller($source . ucfirst($segment1)) || $this->is_controller($source . $segment1))) {
$is_module_controller = true;
}
// module/directory
if ($segment1 && is_dir($source . $segment1 . '/')) {
$is_module_directory = true;
$source = $source . $segment1 . '/';
$subdirectory = $this->directory . $segment1 . '/';
// module/directory (deault_controller = directory)
if ($this->is_controller($source . ucfirst($segment1)) || $this->is_controller($source . $segment1)) {
$is_module_directory_default_controller = true;
}
// module/directory/controller
if ($segment2 && ($this->is_controller($source . ucfirst($segment2)) || $this->is_controller($source . $segment2))) {
$is_module_directory_controller = true;
}
}
// module (deault_controller = module)
if ($this->is_controller($source . ucfirst($segment0)) || $this->is_controller($source . $segment0)) {
$is_module_default_controller = true;
}
/*
// This is the original logic.
if ($is_module_controller) {
return array_slice($segments, 1);
} elseif ($is_module_directory) {
$this->directory = $subdirectory;
if ($is_module_directory_default_controller) {
return array_slice($segments, 1);
} elseif ($is_module_directory_controller) {
return array_slice($segments, 2);
}
} elseif ($is_module_default_controller) {
return $segments;
}
*/
// This is the modified logic, Ivan Tcholakov, 16-JUN-2012.
$result = false;
if ($is_module_controller && $is_module_directory && ($is_module_directory_default_controller || $is_module_directory_controller)) {
$this->directory = $subdirectory;
if ($is_module_directory_default_controller) {
$result = array_slice($segments, 1);
} elseif ($is_module_directory_controller) {
$result = array_slice($segments, 2);
}
} elseif ($is_module_controller) {
$result = array_slice($segments, 1);
} elseif ($is_module_directory) {
$this->directory = $subdirectory;
if ($is_module_directory_controller) {
$result = array_slice($segments, 2);
} elseif ($is_module_directory_default_controller) {
$result = array_slice($segments, 1);
}
} elseif ($is_module_default_controller) {
$result = $segments;
}
if ($result !== false) {
return $result;
}
//
}
}
// Application controller exists?
if ($this->is_controller(APPPATH . 'controllers/' . ucfirst($segment0)) || $this->is_controller(APPPATH . 'controllers/' . $segment0)) {
return $segments;
}
// Application sub-directory controller exists?
if ($segment1 && ($this->is_controller(APPPATH . 'controllers/' . $segment0 . '/' . ucfirst($segment1)) || $this->is_controller(APPPATH . 'controllers/' . $segment0 . '/' . $segment1))) {
$this->directory = $segment0 . '/';
return array_slice($segments, 1);
}
// Application sub-directory default controller exists?
//.........这里部分代码省略.........
示例11: locate
/** Locate the controller **/
public function locate($segments)
{
/**
* Load the site ref for multi-site support
*/
if (!defined('SITE_REF')) {
require_once BASEPATH . 'database/DB' . EXT;
if (DB()->table_exists('core_sites')) {
$site = DB()->where('domain', SITE_DOMAIN)->get('core_sites')->row();
$locations = array();
// Check to see if the site retrieval was successful. If not then
// we will let MY_Controller handle the errors.
if (isset($site->ref)) {
foreach (config_item('modules_locations') as $location => $offset) {
$locations[str_replace('__SITE_REF__', $site->ref, $location)] = str_replace('__SITE_REF__', $site->ref, $offset);
}
// Set the session config to the correct table using the config name (but removing 'default_')
$this->config->set_item('sess_table_name', $site->ref . '_' . str_replace('default_', '', config_item('sess_table_name')));
// The site ref. Used for building site specific paths
define('SITE_REF', $site->ref);
// Path to uploaded files for this site
define('UPLOAD_PATH', 'uploads/' . SITE_REF . '/');
// Path to the addon folder for this site
define('ADDONPATH', ADDON_FOLDER . SITE_REF . '/');
Modules::$locations = $locations;
}
}
}
$this->module = '';
$this->directory = '';
$ext = $this->config->item('controller_suffix') . EXT;
/* 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);
/* 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 and is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory exists? */
if ($directory and is_dir($source . $directory . '/')) {
$source = $source . $directory . '/';
$this->directory .= $directory . '/';
/* module sub-directory controller exists? */
if (is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory sub-controller exists? */
if ($controller and is_file($source . $controller . $ext)) {
return array_slice($segments, 2);
}
}
/* module controller exists? */
if (is_file($source . $module . $ext)) {
return $segments;
}
}
}
/* application controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
return $segments;
}
/* application sub-directory controller exists? */
if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
$this->directory = $module . '/';
return array_slice($segments, 1);
}
/* application sub-directory default controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
$this->directory = $module . '/';
return array($this->default_controller);
}
}
示例12: locate
/** Locate the controller **/
public function locate($segments)
{
$this->module = '';
$this->directory = '';
$ext = $this->config->item('controller_suffix') . EXT;
/* 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);
// =========================================================================
// Replace underscores with dashes
// -- added by Mark Price
$module = str_replace('_', ' ', $module);
$module = str_replace('-', '_', $module);
$controller = str_replace('_', ' ', $controller);
$controller = str_replace('-', '_', $controller);
$directory = str_replace('_', ' ', $directory);
$directory = str_replace('-', '_', $directory);
// =========================================================================
/* 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 and is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory exists? */
if ($directory and is_dir($source . $directory . '/')) {
$source = $source . $directory . '/';
$this->directory .= $directory . '/';
/* module sub-directory controller exists? */
if (is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory sub-controller exists? */
if ($controller and is_file($source . $controller . $ext)) {
return array_slice($segments, 2);
}
// =========================================================================
// If a controller name matches the module name inside the admin directory dont force controller name in URI
// Ex: admin/module/method
// -- added by Mark Price
if ($directory == 'admin') {
if ($controller and is_file($source . $module . $ext)) {
$segments = array_slice($segments, 2);
array_unshift($segments, $module);
return $segments;
}
}
// =========================================================================
}
/* module controller exists? */
if (is_file($source . $module . $ext)) {
return $segments;
}
}
}
/* application controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
return $segments;
}
/* application sub-directory controller exists? */
if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
$this->directory = $module . '/';
return array_slice($segments, 1);
}
/* application sub-directory default controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
$this->directory = $module . '/';
return array($this->default_controller);
}
}
示例13: locate
/**
* Locate the controller.
*
* Used by Modules::load().
*
* @param array $segments The URL segments.
*
* @return array The segments indicating the location of the controller.
*/
public function locate($segments)
{
$this->located = 0;
$ext = $this->config->item('controller_suffix') . '.php';
/* 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) {
if (is_file($source . ucfirst($directory) . $ext)) {
$this->located = 2;
return array_slice($segments, 1);
}
/* 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;
}
}
} elseif (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;
}
foreach (array(APPPATH, IGOPATH) as $searchPath) {
/* application controller exists? */
if (is_file("{$searchPath}controllers/" . ucfirst($module) . $ext)) {
return $segments;
}
/* application sub-directory controller exists? */
if ($directory) {
if (is_file("{$searchPath}controllers/{$module}/" . ucfirst($directory) . $ext)) {
$this->directory = "{$module}/";
return array_slice($segments, 1);
}
/* application sub-sub-directory controller exists? */
if ($controller) {
if (is_file("{$searchPath}controllers/{$module}/{$directory}/" . ucfirst($controller) . $ext)) {
$this->directory = "{$module}/{$directory}/";
return array_slice($segments, 2);
}
}
}
/* application sub-directory default controller exists? */
if (is_file("{$searchPath}controllers/{$module}/" . ucfirst($this->default_controller) . $ext)) {
$this->directory = "{$module}/";
return array($this->default_controller);
}
}
$this->located = -1;
}
示例14: locate
/** Locate the controller **/
public function locate($segments)
{
//echo var_dump($segments).'<br>';
$this->module = '';
$this->directory = '';
$ext = $this->config->item('controller_suffix') . EXT;
/* 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);
//echo $module.' - '.$directory.' - '.$controller.' -<BR>';
/* check modules */
foreach (Modules::$locations as $location => $offset) {
/*if(is_dir(USERS_DIRECTORY.$location.$module.'/controllers/'))
{
$location = USERS_DIRECTORY.$location;
}*/
//echo $location.$module.'/controllers/'.'<br>';
/* module exists? */
if (defined("USERS_DIRECTORY") && is_dir(USERS_DIRECTORY . $location . $module . '/controllers/') || is_dir($location . $module . '/controllers/')) {
$source = $location . $module . '/controllers/';
$this->module = $module;
$this->directory = $offset . $module . '/controllers/';
/* module sub-controller exists? */
//echo "@@".$source.$directory.$ext."@@<br>";
if ($directory and @fopen($source . $directory . $ext, 'r', TRUE)) {
return array_slice($segments, 1);
}
/* module sub-directory exists? */
//echo $source.$directory.'/'.'<br>';
if ($directory and is_dir($source . $directory . '/')) {
$source = $source . $directory . '/';
$this->directory .= $directory . '/';
/* module sub-directory controller exists? */
if (@fopen($source . $directory . $ext, 'r', TRUE)) {
return array_slice($segments, 1);
}
/* module sub-directory sub-controller exists? */
if ($controller and @fopen($source . $controller . $ext, 'r', TRUE)) {
return array_slice($segments, 2);
}
}
//echo $source.$module.$ext.'<br>';
/* module controller exists? */
if (@fopen($source . $module . $ext, 'r', TRUE)) {
return $segments;
}
}
}
/* application controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
return $segments;
}
/* application sub-directory controller exists? */
if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
$this->directory = $module . '/';
return array_slice($segments, 1);
}
/* application sub-directory default controller exists? */
if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
$this->directory = $module . '/';
return array($this->default_controller);
}
}
示例15: locate
/** Locate the controller **/
public function locate($segments)
{
/**
* Load the site ref for multi-site support if the "sites" module exists
* and the multi-site constants haven't been defined already (hmvc request)
*/
if ($path = self::is_multisite() and !defined('SITE_REF')) {
require_once BASEPATH . 'database/DB' . EXT;
# deprecated Remove this for 2.3, as this was too early for a migration
if (!DB()->table_exists('core_domains')) {
// Create alias table
DB()->query('
CREATE TABLE `core_domains` (
`id` int NOT NULL AUTO_INCREMENT,
`domain` varchar(100) NOT NULL,
`site_id` int NOT NULL,
`type` enum("park", "redirect") NOT NULL DEFAULT "park",
PRIMARY KEY (`id`),
KEY `domain` (`domain`),
UNIQUE `unique` (`domain`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ');
}
$site = DB()->select('site.name, site.ref, site.domain, site.active, alias.domain as alias_domain, alias.type as alias_type')->where('site.domain', SITE_DOMAIN)->or_where('alias.domain', SITE_DOMAIN)->join('core_domains alias', 'alias.site_id = site.id', 'left')->get('core_sites site')->row();
// If the site is disabled we set the message in a constant for MY_Controller to display
if (isset($site->active) and !$site->active) {
$status = DB()->where('slug', 'status_message')->get('core_settings')->row();
define('STATUS', $status ? $status->value : 'This site has been disabled by a super-administrator');
}
// If this domain is an alias and it is a redirect
if ($site and $site->alias_domain !== null and $site->alias_type === 'redirect' and str_replace(array('http://', 'https://'), '', trim(strtolower(BASE_URL), '/')) !== $site->domain) {
$protocol = !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
// Send them off to the original domain
header("Location: {$protocol}://{$site->domain}{$_SERVER['REQUEST_URI']}");
exit;
}
// Check to see if the site retrieval was successful. If not then
// we will let MY_Controller handle the errors.
if (isset($site->ref)) {
// Set the session config to the correct table using the config name (but removing 'default_')
$this->config->set_item('sess_table_name', $site->ref . '_' . str_replace('default_', '', config_item('sess_table_name')));
// The site ref. Used for building site specific paths
define('SITE_REF', $site->ref);
// Path to uploaded files for this site
define('UPLOAD_PATH', 'uploads/' . SITE_REF . '/');
// Path to the addon folder for this site
define('ADDONPATH', ADDON_FOLDER . SITE_REF . '/');
// the path to the MSM module
define('MSMPATH', str_replace('__SITE_REF__', SITE_REF, $path));
}
}
// we aren't running the Multi-Site Manager so define the defaults
if (!defined('SITE_REF')) {
// The site ref. Used for building site specific paths
define('SITE_REF', 'default');
// Path to uploaded files for this site
define('UPLOAD_PATH', 'uploads/' . SITE_REF . '/');
// Path to the addon folder for this site
define('ADDONPATH', ADDON_FOLDER . SITE_REF . '/');
}
// update the config paths with the site specific paths
self::update_module_locations(SITE_REF);
$this->module = '';
$this->directory = '';
$ext = $this->config->item('controller_suffix') . EXT;
/* 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);
/* 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 and is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory exists? */
if ($directory and is_dir($source . $directory . '/')) {
$source = $source . $directory . '/';
$this->directory .= $directory . '/';
/* module sub-directory controller exists? */
if (is_file($source . $directory . $ext)) {
return array_slice($segments, 1);
}
/* module sub-directory sub-controller exists? */
if ($controller and is_file($source . $controller . $ext)) {
return array_slice($segments, 2);
}
}
/* module controller exists? */
if (is_file($source . $module . $ext)) {
return $segments;
}
}
}
//.........这里部分代码省略.........