I have a admin folder set up in my controllers directory, under that i have 3 seperate sub-folders with controllers inside of them.
-- Controllers
---- Admin
This code was already on the internet but i modified it to make it work for codeigniter 2.1
See the old source here: http://glennpratama.wordpress.com/2009/10/20/multi-level-subfolder-for-controller-in-codeigniter/
Make a new file MY_Router.php in the application/core directory, copy the following code in it:
set_directory($segments[0]);
$segments = array_slice($segments, 1);
/* ----------- ADDED CODE ------------ */
while(count($segments) > 0 && is_dir(APPPATH.'controllers/'.$this->directory.$segments[0]))
{
// Set the directory and remove it from the segment array
//$this->set_directory($this->directory . $segments[0]);
if (substr($this->directory, -1, 1) == '/')
$this->directory = $this->directory . $segments[0];
else
$this->directory = $this->directory . '/' . $segments[0];
$segments = array_slice($segments, 1);
}
if (substr($this->directory, -1, 1) != '/')
$this->directory = $this->directory . '/';
/* ----------- END ------------ */
if (count($segments) > 0)
{
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().'/'.$segments[0].EXT))
{
show_404($this->fetch_directory().$segments[0]);
}
}
else
{
$this->set_class($this->default_controller);
$this->set_method('index');
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().'/' .$this->default_controller.EXT))
{
$this->directory = '';
return array();
}
}
return $segments;
}
show_404($segments[0]);
}
}