CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

Default controller subdirectory (worked in 2.1.4 but not in the latest 3.0.0/release)

Open zentaos opened this issue 12 years ago • 7 comments

Hello,

I just updated to the latest 3.0.0/release build but the default controller doesn't working anymore if the controller is in a subdirectory.

$route['default_controller'] = 'page/news'; $route['404_override'] = 'error_404'; $route['translate_uri_dashes'] = FALSE;

I hope you can fix this.

Thank you.

zentaos avatar Jan 29 '14 15:01 zentaos

Is 'page' a directory?

narfbg avatar Jan 29 '14 15:01 narfbg

Yes. http://i.imgur.com/W2rGlqV.png

The other routes works fine: $route['u/([a-z]+)'] = 'u/$1'; $route['u/([a-z]+)/(:any)'] = 'u/$1/$2'; $route['([a-z]+)'] = 'page/$1'; $route['([a-z]+)/(:any)'] = 'page/$1/$2';

zentaos avatar Jan 29 '14 15:01 zentaos

Then it's working just fine, 'default_controller' can be either just the controller name or a controller/method pair. That you had it working with a directory in 2.1.x is a bug and not the intended behavior.

3.0-dev is actually for the first time allowing you (not because of a bug) to have a per-directory default controller. That is, if your URI contains only directories, CI will detect that and would look for your default controller under that path. Pseudo code describing the behavior:

// assume $route['default_controller'] = 'news';
if (is_dir($uri))
{
    if (file_exists($uri.'/News.php')) // load default controller
    else // trigger 404
}

narfbg avatar Jan 29 '14 15:01 narfbg

Strange thing, but having the same issue.

If you say that it was a bug in version 2.1.x, why do the folder structure working for custom routes, but not the default one?!

Assume the path if following: /application/controller/admin/Control.php Route that working fine: $route['admin'] = 'admin/control/index'; Default controller not working: $route['default_controller'] = 'admin/control/index';

So, how should we set the default controller, without throwing a PHP file just in "controller" folder?!

Thanks!

xtcsvirus avatar Mar 10 '14 21:03 xtcsvirus

If you say that it was a bug in version 2.1.x, why do the folder structure working for custom routes, but not the default one?!

Because it's how the web works, it's hierarchical.

You're looking at controller directories the wrong way - they are not just tools to organize your code, a request's path is supposed to match a real file path. If you consider a route to be a "redirect", it might make sense to "redirect" a user's request, but it doesn't make sense to redirect in your index page.

Plus, this allows you to have a default controller per directory and solves the problem of CI trying to guess if you've configured a "directory/class" or a "class/method" pair for default controller. The first was never intended, the latter is encouraged.

So, how should we set the default controller, without throwing a PHP file just in "controller" folder?!

You don't.

narfbg avatar Mar 11 '14 08:03 narfbg

so on the CI3 you "can't" change default_controller on sub-directory? is this feature really disabled? :( dude... really? :(

seputrodimas avatar Apr 29 '15 15:04 seputrodimas

Yes, really.

Please ask your questions on the forum boards, not here.

narfbg avatar Apr 29 '15 15:04 narfbg