Welcome Guest, Not a member yet? Register   Sign In
Controllers in subfolders, How do I specify an index?
#1

[eluser]jhyland[/eluser]
I was making a controller "admin.php", thinking it wouldn't get all THAT long.. Well now its about 2000 lines of code, so its time to break it down.

I created an application/controllers/admin folder for all admin controllers, and then, for example, a application/controllers/admin/accounts.php controller that will process all account related admin functions.

My question is, when they just go to mysite.com/index.php/admin/ .. That puts them into the admin folder, but how can I specify a default controller for that folder?

Thanks in advance.
#2

[eluser]adamck[/eluser]
I think you need to set something in the Routes config for that.
Code:
$route['admin'] = "admin/yourindex";

This will make
http://yoursite.com/admin

load 'application/controllers/admin/yourindex.php'
#3

[eluser]jhyland[/eluser]
[quote author="adamck" date="1352813344"]I think you need to set something in the Routes config for that.
Code:
$route['admin'] = "admin/yourindex";

This will make
http://yoursite.com/admin

load 'application/controllers/admin/yourindex.php'[/quote]

Hah, you're awesome! Thanks champ
#4

[eluser]Go-Trex[/eluser]
There is an explanation in the official user guide about placing controllers in sub-folders. You can find the explanation here: http://ellislab.com/codeigniter/user-gui...subfolders

I use this method for a while now and most of the times it is suitable, but when you are combining this with a multi-language interface where the first uri-segment is the countrycode you need to make changes to the default routes.

Keep that in mind for future projects.
#5

[eluser]Aken[/eluser]
In newer versions of CI, the $route['default_controller'] option will be used as a default if one is set. For example:

Code:
// routes.php
$route['default_controller'] = 'home';

// controller file structure:
controllers/
-- admin/
---- home.php // should load when /admin/ URI is called
---- accounts.php // /admin/accounts URI
-- home.php // yoursite.com default controller
-- other.php
#6

[eluser]ahmed.alsiddig[/eluser]
me too need this

thanks for helping guys




Theme © iAndrew 2016 - Forum software by © MyBB