Welcome Guest, Not a member yet? Register   Sign In
Behavior of default controllers in sub-folders
#1

[eluser]Bryan Zera[/eluser]
NOTE: My default_controller is set to 'main'

In the app that I'm developing, the URL

Code:
phonebook/

successfully loads the index function from the file

Code:
controllers/phonebook/main.php

Ideally, the URL

Code:
phonebook/view_departments/123

would point to the view_departments function of

Code:
controllers/phonebook/main.php

but instead it looks for the 123 function in the file

Code:
controllers/phonebook/view_departments.php

Which errors out because the file 'view_departments.php' doesn't exist. In order to get to the view_departments function, I have to explicitly put the default controller in the URL

Code:
phonebook/main/view_departments/123

My dream is that CI to be smart enough to know that if it doesn't find the 'view_departments' segment as a controller, it should pass it as a function name to the default controller.

While I bang away at some routes to solve the problem, has anyone else had this problem and if so, how did you circumnavigate having to explicitly declare the default controller in the URL when you put your controllers in subdirectories?
#2

[eluser]Bryan Zera[/eluser]
Ok, I found a workaround for those interested. Use the following two lines of routing:

$route['phonebook/admin/(.*)'] = "phonebook/admin/$1";
$route['phonebook/(:any)/(:any)'] = "phonebook/main/$1/$2";

The first line picks up any requests to your admin controller (and is redundant, but necessary).

The second line grabs any other traffic and explicitly calls the default controller, all while your URLs stay blissfully free of the default controller.




Theme © iAndrew 2016 - Forum software by © MyBB