4

I have a controller in a subfolder. CodeIgniter is giving a 404 page not found.

The controller works fine in the root controller folder. The controller also works fine in the 1st level subfolder. The controller breaks in the 2nd level subfolder.

Why would CodeIgniter not want you to user multiple subfolders?

Example:

Works: controllers/pages/HomeController.php

Broken: controllers/pages/users/HomeController.php

My Routes are like this:

Works: $route['default_controller'] = "pages/HomeController";

Broken: $route['default_controller'] = "pages/users/HomeController";

1

2 Answers 2

9

I wrote about this before, you just need to read the CI manual, but here is a quick blog entry I did which should get you back on track:

http://blog.biernacki.ca/2011/12/codeigniter-uri-routing-issue-with-controller-folders/

Example:

$route['account/manage/(:num)/(:any)']  = "account/manage/index/$1/$2";
Sign up to request clarification or add additional context in comments.

3 Comments

I read your post, and I'm not clear what you are naming your actual controller object. Is it "Manage"? And then in Manage you just manually reroute to the controller you want?
And why does CI not allow multiple level subfolders?
controller is called manage it is right there in the post...? there is nothing that it 'doesn't allow' it just needs to be routed properly as the default is controller/method/values, the example above is folder/controller/method(index)/value/value (right hand side)
0

CodeIgniter does not inherently allow for multiple controller folders. It may or may not work, but it is an undocumented quirk. Using the routes.php file you can virtualize any folder or controller structure you want, just take care to map your routes back to a controller and method in the Controllers folder.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.