Вот что у меня есть, поместите это в папку «application / core» как MY_Router.php
Он преобразует все в вашем URL в _.
<?php
class MY_Router extends CI_Router {
function set_class($class)
{
$this->class = $this->replace_underscores($class);
}
function set_method($method)
{
$this->method = $this->replace_underscores($method);
}
private function replace_underscores($string){
return str_replace('-', '_', $string);
}
function _validate_request($segments)
{
$this->segments = $segments;
if(empty($this->segments) || $this->controller_is_in_root_folder())
return $this->segments;
if ($this->controller_is_in_a_subfolder())
{
$this->segments = $this->set_directory_and_remove_from_array();
if ($this->at_least_one_segment() > 0 && !$this->default_controller_is_in_subfolder())
{
show_404($this->fetch_directory().$this->segments[0]);
}
else
{
$this->set_class($this->default_controller);
$this->set_method('index');
if (!$this->default_controller_is_in_subfolder())
{
$this->directory = '';
return array();
}
}
return $this->segments;
}
else
show_404($this->segments[0]);
}
private function at_least_one_segment(){
return count($this->segments) >= 1;
}
private function controller_is_in_a_subfolder(){
return is_dir(APPPATH.'controllers/'.$this->segments[0]);
}
private function controller_is_in_root_folder(){
return file_exists(APPPATH.'controllers/'.str_replace('-', '_', $this->segments[0]).EXT);
}
private function set_directory_and_remove_from_array(){
$this->set_directory($this->segments[0]);
return array_slice($this->segments, 1);
}
private function default_controller_is_in_subfolder(){
return file_exists(APPPATH.'controllers/'.$this->fetch_directory().str_replace('-', '_', $this->segments[0]).EXT);
}
}