![]() |
Using nested controllers - 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: Using nested controllers (/showthread.php?tid=23847) |
Using nested controllers - El Forum - 10-23-2009 [eluser]hollow[/eluser] Hello, First time here, just started using CI and enjoying it. Issue: I'm trying to use nested controllers, something like this: controllers/welcome.php controllers/private/welcome.php controllers/private/students/marks.php controllers/private/management/marks.php Sure, I can avoid this by trying this structure: /controllers/welcome.php /controllers/students/marks.php /controllers/management/marks.php But, could I achieve my first goal? How should my routes.php look like? To reach the controllers/private/welcome.php it works with: Code: $route['private'] = "private/welcome"; Thank you. Using nested controllers - El Forum - 10-23-2009 [eluser]bretticus[/eluser] Routes work by taking a non-standard URI and converting it to a standard one. You are trying to take a non-standard URI and convert it to a non-standard URI. I don't think CI was intended to work with the notion on sub or nested controllers. There is the notion of modules that is similar to what you are attempting (maybe exactly what you are looking for.) It involves extending the framework somewhat see Matchbox or HMVC. Using nested controllers - El Forum - 10-23-2009 [eluser]hollow[/eluser] Thank you for your prompt answer. It's a quite small application, I don't know if I should use modules in the way you pointed me, especially now, as a beginner. I've read about HMVC, but, regarded simply in a structural way, without the benefits of the library, wouldn't it be the same as in the alternative in my first post? Maybe now I can have two levels of folders in my controllers, but I'm losing my private/welcome.php (as in my alternative), which is the same for all the modules. My controllers/ contains only one public page, for authentication primarily, after being authenticated, I redirect the user to controllers/private/welcome.php, which has a menu and a welcome message... From there on, the user selects a module (students), which maps to a menu with several submenu items, for various tasks. All the controllers for the students module should be placed in controlles/private/students/. Am I asking too much? Thanks. Using nested controllers - El Forum - 10-23-2009 [eluser]bretticus[/eluser] I think you are just going about it the wrong way. Why not have a private.php controller in application/controllers ? You simply need a welcome method and a student method (etc.) You can password protect just that controller. Using nested controllers - El Forum - 10-23-2009 [eluser]hollow[/eluser] I think you are right, I could do this more easy. I'm going with: /welcome.php /privat.php /students/marks.php /teachers/marks.php After login, the url will be: www.example.com/privat After selecting an item from the menu, it will go to www.example.com/students/marks, without the private word, I really don't mind. I won't go with methods inside privat.php, there are just to many, and each method has to be itself a controller.. I might have www.example.com/students/marks/list, so I need them as classes. Thanks again for your support. Using nested controllers - El Forum - 10-24-2009 [eluser]InsiteFX[/eluser] Hi, If you read the user guide it will answer this for you! URI Routes Enjoy InsiteFX |