Passing URL Parameters to Default Control With _Remap |
[eluser]craig.hoog[/eluser]
I know this defeats alot of the purpose of using CodeIgniter, but I really want to use the framework for the project I have. Unfortunately the project requires URL parameters to be passed immediately after the base URL. In Example: www.example.com/john.casey - Where John.Casey is the parameter being passed in. Is it possible to do this? I have tried adding a remap to the default controller, but it obviously looks for the john.casey controller when you navigate to that URL. Thanks in advance, Craig
[eluser]n0xie[/eluser]
Extend the Router class. Overwrite function _validate_request by copy pasting it into MY_Router.php and change line 239 to load a controller instead of show_404(). In this controller grab the url and do a database lookup.
[eluser]craig.hoog[/eluser]
Thanks for the quick response. I have the library extended and have copied the function over. My last question (ideally) would be the best way to redirect that to the default controller and keep the parameters passed through. I assume a redirect would just endlessly loop through this function as it revalidates?
[eluser]n0xie[/eluser]
No need to redirect. Just pass the controller you want to load as parameter to $segments
[eluser]craig.hoog[/eluser]
What I am doing is: $segments[1] = $segments[0]; $segments[0] = 'defaulted'; return $segments; I assume I am doing this wrong. EDIT: Despite the fact that this is probably not the best way to do it, this actually did work.
[eluser]WanWizard[/eluser]
You can also do this using a normal route, just make sure you'll make it the last one: Code: $routes['(.*)'] = 'default/index/$1';
[eluser]craig.hoog[/eluser]
I ended up using your code for this one WanWizard (changing $routes to $route). However, it doesn't seem to support multiple URI segments. Is there a simple way to allow the same concept to pass 2 URI segments so I can pass two URI segments to the default controller just after the URL? ie: www.example.com/spies/john.casey -- Looks for John.Casey in the Spies table. Neither method above seems to work for this.
[eluser]sophistry[/eluser]
FYI - _remap() is now passed all URI segments as an array - see CI 2.0 at BitBucket. |
Welcome Guest, Not a member yet? Register Sign In |