CodeIgniter Forums

Full Version: Using Sub-Directories for Default_controller
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Everyone, Apologies if this has been asked and answered else where but I couldn't find anything.

Basically, when setting the default controller to:

PHP Code:
$route['default_controller'] = 'welcome'

everything works as expected but as soon as I set the default controller to a file within a sub directory it doesn't work as per below:

PHP Code:
$route['default_controller'] = 'admin/dashboard'

The file has an index() function therefore accessing the method/function is not a problem and I've also tried the following just in case:

PHP Code:
$route['default_controller'] = 'admin/dashboard/index'

It definitely worked in codeigniter 2.4 but from a little bit of reading online it appears this has been changed in codeigniter 3, is there anything I can do to rectify this?

Thanks
Chris
As far as I understand, the default_controller would not work with subdirectories, look here:
https://github.com/bcit-ci/CodeIgniter/issues/2849

As narfbg mentioned:


Quote:Then it's working just fine, 'default_controller' can be either just the controller name or a controller/method pair. That you had it working with a directory in 2.1.x is a bug and not the intended behavior.
As far as i know,

You should use your controller name at first , then you can also use the name of a function inside it



PHP Code:
$route['default_controller'] = 'coltroller/function'


so in your case you should have a controller admin.php in your `controllers` folder, which has the function `dashboard` inside it

----

You can also do this:


PHP Code:
$route['default_controller'] = 'welcome'

Then inside your welcome controller do a simple redirect


PHP Code:
redirect("admin/dashboard");