Folder structure for controllers |
[eluser]pan69[/eluser]
Hi guys. I'm working a somewhat largish site and I really need to subdivide my controllers folder into sub-directories. If I don't I get a whole bunch of incoherent files sitting in one folder which is going to do my head in. So e.g., In the 'Settings' section of my site I have a whole bunch options. I'd like to arrange the controllers for all these options in the 'settings' sub-folder of the controllers folder. However, out of the box this is going to clash. When I call ~/settings/users I actually want to call the Users controller in the controllers/settings folder. Is this possible? Thanks, Luke
[eluser]Aken[/eluser]
Of course you can. It's explained in the User Guide: http://ellislab.com/codeigniter/user-gui...llers.html Look for Organizing Your Controllers into Sub-folders
[eluser]pan69[/eluser]
Ah. Somehow I looked completely past that. Thanks! Any idea how to handle the following situation. In controllers/ I have a settings.php controllers. Next to that I have a settings/ folder containing all the settings sub-category controllers. With the settings.php in the controllers/ folder there seems to be a clash between the controller and sub-folder. Any ideas how to handle that situation (without renaming one or the other). Thanks!
[eluser]Bramme[/eluser]
I believe I have read about this once in the past (somebody handled his applications like this) and I think it works right out of the box. You should give it a whirl. If it's not working, you might have to use some routes. (routing settings/ to setttings/index for example...)
[eluser]pan69[/eluser]
Figured it out. What you do is this: Say you want have a section called 'Settings' and you want all the controllers for this section to live in a folder called settings/ inside you controllers/ folder. In the controllers folder create a folder called settings/. If you already have a controller called settings.php in your controller/ folder than this will clash. Move your settings.php controller (or create it) in the settings/ folder and rename it to your default controller as specified in the routes.php configuration file. Mine happens to be index.php If you now browse to yourdomain.com/settings you will see that the default controller (index.php) inside the settings/ folder is executed. I assume that this technique will also work on deeper structures but I haven't tried that yet. Hope this helps...
[eluser]Bramme[/eluser]
It sure does! Thanks for the small research. I'd love to see a library that would extend CI's subfoldering (if you can make a verb from that :p), the ability to set default controllers on a subdirectory basis etc. would be awesome!
[eluser]pan69[/eluser]
[quote author="Bramme" date="1224552689"].the ability to set default controllers on a subdirectory basis etc. would be awesome![/quote] Yeah. It would be a nice to have. I'd rather see domain specific configurations however...
[eluser]sophistry[/eluser]
[quote author="Bramme" date="1224552689"]the ability to set default controllers on a subdirectory basis etc. would be awesome![/quote] why not use custom routes? one per subdir? OTTOMH (as in, not tested!) Code: $route['subdir/(:any)']='subdir/default_controller/$1';
[eluser]Pascal Kriete[/eluser]
Or just extend the router. I have used the following on pretty much everything I've done. It assumes that the default controller file has the same name as the subfolder. So calling example.com/settings will go to controllers/settings/settings.php, and execute the index method. Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
Welcome Guest, Not a member yet? Register Sign In |