Welcome Guest, Not a member yet? Register   Sign In
Default controller problem with controller in a subfolder
#1

[eluser]Macros[/eluser]
This seems to have been mentioned before, but still seems to be a bug 1.6.2.

Basically, if the default controller looks like:
Code:
$route['default_controller'] = "folder/controller";

Then the class file is loaded... but the class can't be found.

CodeIgniter.php:
Code:
Line 154: include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
Line 169: $class  = $RTR->fetch_class();

Using the route above, then
Code:
$class = 'folder/controller'
Code:
Line 173: if ( ! class_exists($class)...

This will return false, as the class name being checked is "folder/controller", but the REAL class name is "controller", and it was loaded in the include line.

Cameron.
#2

[eluser]Pascal Kriete[/eluser]
Yup, I run into this one everytime a project grows large enough to warrant the use of folders. The fix is quite a simple one.

In system/libraries/router.php:
Code:
// function _set_routing

/* .... */

if ($this->default_controller === FALSE)
{
    show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file.");
}

/* Change Start */
            
$parts = explode('/', $this->default_controller);
            
if ( count($parts) > 1)
{
    $this->set_directory( current($parts) );
}
            
$this->set_class( end($parts) );
$this->set_method('index');
$this->_set_request($parts);

/* Change End */

// Re-index the routed segments array so it starts with 1 rather than 0
$this->uri->_reindex_segments();

/* .... */

I've had something like this in my MY_Router file for a while now.
#3

[eluser]Unknown[/eluser]
The bug is still present in 1.6.3.
Inparo's fix works great - thank you
#4

[eluser]Vanilla Junior[/eluser]
Thank you for the excellent fix.




Theme © iAndrew 2016 - Forum software by © MyBB