I am using CodeIgniter framework. I have files in my controllers folder like this:
- Controllers
--- admin.php - Admin Controller
--- /Admin - Admin Folder
----- category.php - Category Controller in Admin folder.
The Url: mysite.com/index.php/admin/category says that page not found because it is trying to call the category function of admin controller but I want it to call the index function of category controller in Admin folder.
Also I am using the admin controller for create, edit etc. functions of admin controller like mysite.com/index.php/admin/create.
I think, I should use the $route array in config file. What routing should I use?
This is the default behavior of the CI core. See
function _validate_request($segments)insystem/core/Router.php. This function attempts to determine the path to the controller. It goes through different conditions one by one and returns the result once a given condition is met. Besides the other, there are two conditions involved:Is it a file? (
system/core/Router.phpline 271, CI 2.1.2)Is it a folder? (
system/core/Router.phpline 277, CI 2.1.2)In your case the function will return once the first of the two conditions is met, i.e. when
admin.phpfile is found.There are two solutions:
Change the default behavior by extending the core. Basically that would conclude in changing the sequence of conditions checking. This can be accomplished by creating
MY_Routerclass:and rewriting the original
_validate_request()function with changed sequence of conditions. So first checking for directory and then for function.I would suggest the first solution, if it does not require too much refactoring.