overriding default controller via $routing[] in index.php can't call methods other than index |
[eluser]taber[/eluser]
I have an /admin directory set up with a basic auth .htaccess and this index.php (snippet) in it: Code: /* Loading up /admin/ in my browser works fine, but if I try /admin/somethingelse/ I get an Apache 404 error (not a custom 404). So I tried 2 things at this point: 1) Using routes.php to redirect /admin/somethingelse/ to /any_other_controller as a test. Routing is apparently totally ignored at this point. 2) Using mod_rewrite in .htaccess to redirect /admin/* requests to /index.php?/admin/$1 - which WORKS, except it looks like my custom config assignment doesn't get set. ![]() Has anyone else seen this? I think everything would be fine if either #1 or #2 worked as expected. PS: I know the comment says "The controller class file name. Example: Mycontroller.php" but adding ".php" doesn't work. Just a side note. Doesn't seem to make a difference w/ my issue. ![]() Edit: Okay, I tried commenting out those lines and not overriding the default controller. Except now I'm unable to call any methods other than index on my site's default controller. (The other pages 404.) ![]() ![]()
[eluser]InsiteFX[/eluser]
You cannot override the default controller you have to have a default controller! The best thing to do when using admin etc is to create a MY_Controller and extend all your other controllers from that! Also you can rename the default controller to whatever you want. InsiteFX
[eluser]taber[/eluser]
[quote author="InsiteFX" date="1306404976"]You cannot override the default controller you have to have a default controller! The best thing to do when using admin etc is to create a MY_Controller and extend all your other controllers from that! Also you can rename the default controller to whatever you want. InsiteFX[/quote] Well I don't really want to override the site's default controller per se... just force my /admin/index.php to use my "Admin" controller (and any other methods I create under it). For example, I hit http://mysite.com/admin/delete/3 and expect it to use my Admin controller's "delete" method: Code: function delete($id) { This is the key part that I'm trying to get to work (from the comments of index.php) Quote:* IMPORTANT: If you set the routing here, NO OTHER controller will be (Emphasis mine.) I should also mention I'm using CI 2.0.2.
[eluser]InsiteFX[/eluser]
Then what you need is to use routes. This is how I have mine setup, should be a good example for you. Code: $route['login'] = "admin/admin/login"; Where the first admin is controllers/admin directory Then admin.php and the methods in admin.php login, logout, register and index if you need to pass parameters then it is something like this: Code: $route['login/(:num)'] = "admin/admin/login/$1"; InsiteFX |
Welcome Guest, Not a member yet? Register Sign In |