![]() |
Controller Subfolders - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Controller Subfolders (/showthread.php?tid=4982) |
Controller Subfolders - El Forum - 12-28-2007 [eluser]adamp1[/eluser] Quick question here. How many folders deep can controllers be put in? Is it only one or can I have many levels. Reason for me asking is I want the following Code: controllers/admin/system Now the admin folder holds all controllers for the admin area (like the default landing controller), while the admin/system folder holds all controllers specific to the controllers which deal with system functionaly (settings,users etc)? So is what I want possible? Controller Subfolders - El Forum - 12-28-2007 [eluser]Michael Ekoka[/eluser] one Controller Subfolders - El Forum - 12-28-2007 [eluser]adamp1[/eluser] OK cheers for clearing that up, will just have to have a super large controller then. Controller Subfolders - El Forum - 12-28-2007 [eluser]Michael Ekoka[/eluser] why use a super large controller, when you can create many base controllers in your application/libraries/MY_Controller.php file. http://ellislab.com/forums/viewthread/67463/ BTW when i say one i mean one folder deep after the controllers directory. However you need to be aware of a bug in CI regarding this: http://ellislab.com/forums/viewthread/50795/ http://codeigniter.com/bug_tracker/bug/2849/ Controller Subfolders - El Forum - 12-28-2007 [eluser]adamp1[/eluser] Because that would take the controllers away from the controller folder, would mean changing things in the future would be more complex (in the fact that I would forget they were there) Also I'm trying to as much as possible not spread my code around too much since if I do release it I want similar code to be in the same place. Controller Subfolders - El Forum - 12-28-2007 [eluser]Michael Ekoka[/eluser] Using base controlles provides you with great amount of flexibility, this is what MVC and OO programming is about. You don't have to create your base controllers in application/libraries/MY_Controller.php, you can move them and later include them there. Even if you want to package your code I don't see how this can be a problem. Code: Package If you drop the content of such a package in a CI application it will fall right in place. The only extra step you might need would be to connect the Base controllers to your application and this can be done in a simple step: In your application/libraries/MY_Controller.php, just include the All_Base_Controllers.php file (which itself includes the others). Alternatively you can decide to simply include your base controllers at the top of your controllers files if you wish to make everything automatic for someone using your release. in application/libraries/MY_Controller.php Code: include_once 'Base_Controllers/All_Base_Controllers.php'; in application/controllers/admin/management.php Code: // optional. Use this if you don't want to include your Base controllers from the MY_Controller.php file What would your base controllers look like: e.g. your Admin_controller.php would have something like this: Code: class Admin_controller extends Controller{ Then your controllers would just extend the base they need to and be ready to use: controllers/admin/management.php Code: class Management extends Admin_controller{ Code: class Forms extends Admin_controller{ Code: class Login extends Controller{ Code: class Registration extends Application_controller{ Controller Subfolders - El Forum - 12-29-2007 [eluser]adamp1[/eluser] After reading your reply I don't think you quite understood why I wanted sub folders. Ill try to explain what I mean. In my admin area at the top I have a drop down menu system much like ExpressionEngine. One option is Code: System Now for why I wanted to be able to put it in its own sub folder. This was the structure I wanted. Code: admin/ The reason for this mean then all code to do with managing the system is within a single folder. This would mean then you would have a new folder for each parent menu item thus keeping the code modular. So If I wanted to add a menu item to control site pages the structure would be as follws Code: admin/ I could probably do what you said, but then I would be splitting up the code to view the front page of a controller and the inner subfuctions. Which to me seems to complicate the matter. The reason I said I would have to have a large controller is it would have a single controller 'System' which would do the job of the folder (IE keep all code related to system operations together) |