Default Controller Issue - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Default Controller Issue (/showthread.php?tid=29578) |
Default Controller Issue - El Forum - 04-14-2010 [eluser]TheServant[/eluser] I have spent the past 3 hours reading posts on these forums from people who seem to have a similar problem but no solution works. Please can someone have a look and see if you can help: This is my controller: Code: class Page extends Controller { When I use mod_rewrite: Code: <IfModule mod_rewrite.c> / -> Default /page -> Default /page/ -> Default /page/index -> Default /page/index/ -> Default /page/index/home -> Default /page/index/asdasd -> Default I have changed my $config['uri_protocol'] to all of the options with no solution. My $route['default_controller'] = "page"; I have added another route: $route[':any'] = 'page/index'; With variations: $route[':any'] = 'page'; $route[':any'] = 'page/'; $route[':any'] = 'page/index'; $route[':any'] = 'page/index/'; $route[':any'] = 'page/index/$1'; $route['(:any)'] = 'page/index/$1'; All resulting in the Default. I think that some override is happening with the default_controller that it either serves that or nothing (404). I can't run other classes even if I try: index.php/test/index/test (and all the variations) as it continually returns the default from the class defined in the default controller. Any help would be greatly appreciated. This has brought me to utter exhaustion and all the time CI has saved me has been lost Default Controller Issue - El Forum - 04-14-2010 [eluser]mddd[/eluser] Could your 'defaultindex' be causing trouble? I mean, if the server comes across something that is not an existing file (maybe something like /page/index/abc) can't it be that the server will then redirect you to index.php, as that is the default index? Try removing that line and see what happens. Also, to help us understand, is Page your default controller or are you trying to call the Page controller but getting another controller which is your default? Default Controller Issue - El Forum - 04-14-2010 [eluser]TheServant[/eluser] Thanks for your reply. I have deleted defaultindex and no change. Yes, Page is the default controller and I can't get any other. Default Controller Issue - El Forum - 04-14-2010 [eluser]mddd[/eluser] If you remove all your routes except the default controller route, then it should work like this: / -> page controller. index method. default $page: register /somecontroller -> goes to that controller /page/somevalue -> page controller. somevalue method (if it exists). otherwise: 404 error. /page/index -> page controller. index method. default $page: register /page/index/somevalue -> page controller. index method. $page: somevalue If you want this: /page/somevalue -> page controller. index method. $page: somevalue then you must use the _remap method in the page controller. this takes care of any method calls to methods that don't exist: Code: function _remap($vars) So /page/somevalue goes to _remap('somevalue') and that goes on to index('somevalue'). Default Controller Issue - El Forum - 04-14-2010 [eluser]Jelmer[/eluser] I have a similar setup and I have in routes.php: Code: $route[':any'] = 'page'; In my controller I do the processing using a _remap() function: Code: function _remap() This is how I solved it over 2 years ago, I'm not sure anymore why I did it like this and not for instance using $route[':any'] = 'page/index'; - but this works for me, and I can remember similar problems while first writing this setup. Default Controller Issue - El Forum - 04-14-2010 [eluser]TheServant[/eluser] I have solved it for as far as I can see... I have not tried any remap functions but simply used: Code: $route['(:any)'] = 'page/index/$1'; I think that's all I have changed and it seems to be working. Thanks for your replies. If I run into anymore trouble with this I will definitely give _remap() a go. Thanks again. Default Controller Issue - El Forum - 06-28-2010 [eluser]porky_voice[/eluser] i used the route but i can't browse any other page Default Controller Issue - El Forum - 06-29-2010 [eluser]Jelmer[/eluser] When you use the rule with (:any) in there it will match any uri (as one might expect ) - so be very carefull when you use it to define exceptions to the rule, or you won't be able to use other controllers anymore. Also you need to define the exceptions prior to the :any rule, if you don't the :any rule will supercede the other rules and they will never be invoked. Default Controller Issue - El Forum - 06-29-2010 [eluser]porky_voice[/eluser] Thanks for that Jelmer... it's working now.. |