CodeIgniter Forums
Using Sub-Directories for Default_controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Using Sub-Directories for Default_controller (/thread-61713.html)



Using Sub-Directories for Default_controller - ridley1012 - 05-08-2015

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


RE: Using Sub-Directories for Default_controller - Urastor - 05-08-2015

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.



RE: Using Sub-Directories for Default_controller - noobie - 05-08-2015

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");