Organizing Controllers into Sub-Directories |
I'm looking to organize controllers into sub-directories per instructions at http://www.codeigniter.com/userguide3/ge...irectories
However, it doesn't work and I'm not sure what's missing. Going to http://www.foo.com/members goes to the member login page as expected. Going to http://www.foo.com/members/summary gives a 404 error. Putting the logic for summary inside of controllers/Members.php works but there will be many more files and related logic so it's better if I can organize into sub-directories. Folder structure (simplified): Code: -www .htaccess file: Code: RewriteEngine On What is the best to adjust to get this working? the .htaccess file? the routes.php file? readjust the folder structure? something else? Thank you in advance!
You may be able to get this to work with a creative routes.php, but the main problem is probably the fact that you are trying to use a controller and directory with the same name (as far as routing is concerned) at the same level.
In other words, when you go to /members/summary, it looks for a method in your Members controller named summary. If you did not have a Members controller, it would look in the members directory for the Summary controller. As far as I can tell, it will not look for the directory as long as the controller of the same name exists.
I can't test it right now, but going by the instructions, I would have my directory like this.
Code: www In other words, rename Members.php to Login.php and move it from controllers to controllers/members. Then your URLs would be Code: http://localhost/members/login
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
(04-30-2015, 11:59 AM)mwhitney Wrote: You may be able to get this to work with a creative routes.php, but the main problem is probably the fact that you are trying to use a controller and directory with the same name (as far as routing is concerned) at the same level. OK. I pulled it apart and the sub-directory structure works now. The new structure is as follows: Code: -www Thank you @mwhitney. Edit: @RobertSF's response came through while I was composing that response. Thank you @RobertSF as well.
You're welcome! I'm glad you fixed your problem.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
hey fyi - i don't know about CI 3 but with CI 2 you can't have controllers in subfolders -- but this code makes it possible:
https://degreesofzero.com/article/contro...niter.html very clear tutorial -- i use it and it works great. (05-01-2015, 12:10 PM)cartalot Wrote: hey fyi - i don't know about CI 3 but with CI 2 you can't have controllers in subfolders -- but this code makes it possible: Sure you can: http://www.codeigniter.com/userguide2/ge...subfolders You just can't have more than one level of subfolders.
thank you yes -- i should have said this code helps with having "sub sub" folders in the controller
|
Welcome Guest, Not a member yet? Register Sign In |