![]() |
Route URL with GET parameters to cleaner URL - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Route URL with GET parameters to cleaner URL (/showthread.php?tid=12007) |
Route URL with GET parameters to cleaner URL - El Forum - 10-01-2008 [eluser]vendiddy[/eluser] Hi, I am trying to figure out how to reroute a url like application/test?token=123 to a url like application/test/123. This is because the Zend_Gdata library needs to send an authentication token back to a method of my controller in the form of a GET parameter. Code: function test_gcal_auth() I currently use a hack where I set the next url to be test.php. In test.php, I extract the GET parameter and redirect to the correct method in my application controller. (As seen below.) Code: $token = $_GET['token']; Does anyone know of a cleaner solution? I tried adding a regex pattern in routes.php but wasn't able to get it working. Thanks! Route URL with GET parameters to cleaner URL - El Forum - 10-02-2008 [eluser]Phil Sturgeon[/eluser] Im confused about what your trying to achieve and where you are trying to achieve it. You seem to have /application/ and /system/ in your URL's. This is not normal CI behaviour. Anyway, the following code would work: Code: <?php If you could explain your code more I could help you further ![]() Route URL with GET parameters to cleaner URL - El Forum - 10-02-2008 [eluser]vendiddy[/eluser] Sorry for the confusion, but my controller is named application. (Is there a standard for naming the default controller?) Basically, if I paste this URL into my browser: http://localhost/umdcal.php/application/test?token=CPPu5rz7ABCCf-Tq_v____8B I get the 404 page even though I have a function called test in my application controller. Instead of getting this 404 page, I would like for the above URL to automatically redirect to http://localhost/umdcal.php/application/test/CPPu5rz7ABCCf-Tq_v____8B I don't think I can use an alternative to the GET parameter. This is because Google's authentication works by redirecting to a page of my choice and attaching the token as a GET parameter. Thanks again! Route URL with GET parameters to cleaner URL - El Forum - 10-02-2008 [eluser]drewbee[/eluser] Hi Vendiddy, I set up a referral system on one of my CI sites, which allowed the user to take any page / controller / method etc and attach a ?ref=userid to it. What I did assumes that query_string is still set to OFF for CI. in the pre_controller hook, you can still process $_GET as CI hasn't gotten ahold of it yet. Here is what I would do: at this point in time there are only two classes loaded for CI, so you have to use native PHP code for everything I would actually recomend only having this run on the page that can accept this as well. pre_controller hook: Code: if (isset($_GET['token'])) ... or if you think of something else besides a header redirect. Make sure you do the unset() though, that way CI doesn't see it, as it would throw a 404 as you are currently experiencing. Route URL with GET parameters to cleaner URL - El Forum - 10-02-2008 [eluser]drewbee[/eluser] One other thing to try. What happens if you feed google an end slash (after test) IE http://localhost/umdcal.php/application/test/ Does CI then pass: ?token=CPPu5rz7ABCCf-Tq_v____8B to the controller? Or does it try and make a url out of it? IF it does pass that, you could simply strip the ?token= off of it and you have your token string. This would, of course, require you to add additional 'allowed uri characters' Route URL with GET parameters to cleaner URL - El Forum - 11-01-2008 [eluser]Unknown[/eluser] Hi, I'm having the same problem. Is there another workaround that doesn't have to use any hook ? I'm afraid it will have performance problem. Thanks, JarBis |