?
Current Path : /home1/savoy/public_html/savoyglobal.net/chess2015open/application/core/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : /home1/savoy/public_html/savoyglobal.net/chess2015open/application/core/MY_Router.php |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * This class override enhances routing. * * @author Joshua Logsdon * @email joshua@joshualogsdon.com * @filename MY_Router.php * @title Router library override * @url http://www.joshualogsdon.com * @version 1.0 */ Class MY_Router extends CI_Router { function _pluck_directory($segments) { $this->directory = ''; foreach($segments as $segment) { $segment = trim($segment); if($segment != '') { if(is_dir(APPPATH .'controllers/'. $this->directory . $segment)) { $this->directory .= array_shift($segments) .'/'; } else { break; } } else { array_shift($segments); } } // quick and easy forced reindexing $segments = array_values($segments); // put the entire directory path back into the segments as the first item $dir = trim($this->directory, '/'); if(!empty($dir)) { array_unshift($segments, $dir); } $this->segments = $segments; return $segments; } function _validate_request($segments) { $segments = $this->_pluck_directory($segments); $found = TRUE; // Use to test if the controller exists with hyphens switched to underscores $test_segment = str_replace('-', '_', $segments[0]); // Does the requested controller exist in the root folder? if (file_exists(APPPATH.'controllers/'.$test_segment.EXT)) { // Make the change to the controller name permanent $segments[0] = str_replace('-', '_', $segments[0]); // Since we've found the controller, we need to make sure its function call also has hyphens switched to underscores if (isset($segments[1])) { $segments[1] = str_replace('-', '_', $segments[1]); } return $segments; } // Is the controller in a sub-folder? if (is_dir(APPPATH.'controllers/'.$segments[0])) { // Set the directory and remove it from the segment array $this->set_directory($segments[0]); $segments = array_slice($segments, 1); if (count($segments) > 0) { // Use to test if the controller exists with hyphens switched to underscores $test_segment = str_replace('-', '_', $segments[0]); // Does the requested controller exist in the sub-folder? if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$test_segment.EXT)) { $found = FALSE; } else { // Make the change to the controller name permanent $segments[0] = str_replace('-', '_', $segments[0]); // Since we've found the controller, we need to make sure its function call also has hyphens switched to underscores if (isset($segments[1])) { $segments[1] = str_replace('-', '_', $segments[1]); } } } else { $this->set_class($this->default_controller); $this->set_method('index'); // Does the default controller exist in the sub-folder? if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) { $this->directory = ''; return array(); } } if($found) return $segments; } // Can't find the requested controller, so fall back to the default // The default controller would be responsible for either serving a content page or the 404 page. $this->set_directory(''); $this->set_class('pages'); $this->set_method('index'); return array(); } } // END Router Class /* End of file Router.php */ /* Location: ./application/libraries/MY_Router.php */