URI routing question - 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: URI routing question (/showthread.php?tid=5097) |
URI routing question - El Forum - 01-05-2008 [eluser]freshmug[/eluser] Hi, I'm new to codeigniter but a big fan already. I have a question on how to make something work related to URI routing. I have a button on my site that redirects a user to an external site with a callback url. I cannot control the use of query strings in the callback url format. The callback url looks something like: http://www.mysite.com/index.php/mycontroller?auth_token=88797abc89798dd444334 I'm trying to handle this type of query and have it call a "processAuth" function on "mycontroller". So I need to map the above callback to something like: http://www.mysite.com/index.php/mycontroller/processAuth/88797abc89798dd444334 The above call to processAuth works fine. I can't figure out how to use URI routing with reqular expressions to solve this problem. I tried adding various routes like: $route['mycontroller?auth_token=(.+)'] = "mycontroller/processAuth/$1"; $route['mycontroller\?auth_token=(.+)'] = "mycontroller/processAuth/$1"; $route['(mycontroller\?auth_token=)(.+)'] = "mycontroller/processAuth/$2"; Can someone help me out? I'm not even sure I'm on the right track...is there a better/easier way? Thanks in advance. URI routing question - El Forum - 01-06-2008 [eluser]Grahack[/eluser] Quote:I cannot control the use of query strings in the callback url format. The callback url looks something like:Do you mean you don't have control at all and must deal with this format, that is an outer space URL to CI? I guess what you get with http://www.mysite.com/index.php/mycontroller?auth_token=88797abc89798dd444334 is a 404 because CI then looks for a controller named auth_token (without query strings enabled). CI unsets the $_GET array if you don't "enable query strings" (see libraries/Input.php) and I don't think you can grab the value, even in the triggered auth_token controller. If you enable query strings, then refer to the docs at section Enabling Query Strings. I didn't have much good results even with this... Please give feedback! EDIT: I didn't see it was your first post. Welcome here! And for these kind of problems, if you have a local install, don't be afraid to hard-debug CI to understand how it works. When investigating for your problem, I just added some Code: die(APPPATH.'controllers/'.$segments[0]); URI routing question - El Forum - 01-06-2008 [eluser]Craig A Rodway[/eluser] You could probably pass this auth token as a final URI segment with some creative regular expressions in htaccess (using mod_rewrite) instead of in the route. URI routing question - El Forum - 01-06-2008 [eluser]freshmug[/eluser] Yes, I don't have total control over the callback URL: http://www.mysite.com/index.php/mycontroller?auth_token=88797abc89798dd444334 I only control the callback part of it: http://www.mysite.com/index.php/mycontroller The external site I'm calling adds: ?auth_token=88797abc89798dd444334 And I can't control how they pass the auth_token back to me, so I can't make the callback look like: http://www.mysite.com/index.php/mycontroller/88797abc89798dd444334 I'll try to figure out how to use htaccess to rewrite the URL. I'm not familiar with htaccess but will try my best. I'll look into "enabling query strings" if that doesn't work. Thanks for the responses. I'll let you know how it goes. Please let me know if you have any other suggestions/ideas. URI routing question - El Forum - 01-06-2008 [eluser]Grahack[/eluser] After more investigations: without enabling query string, http://test.local/ci/index.php/test?key=val triggers the key controller. In its index() function, you can access the value val in $_REQUEST['key']. URI routing question - El Forum - 01-06-2008 [eluser]Craig A Rodway[/eluser] Ok, I've been playing around with this a bit and after some testing it seems that you can get this to work if you change the URI protocol in config.php to PATH_INFO and use something like this mod_rewrite: Code: RewriteEngine on http://www.example.com/welcome/welcome/?auth_token=abcdef123456 would make: http://www.example.com/welcome/welcome/auth/abcdef123456 If you don't change it to PATH_INFO, it looks like the query string upsets the auto-detection. Also, with default routing in place, if you don't specify a controller and a function it won't work either. URI routing question - El Forum - 01-06-2008 [eluser]freshmug[/eluser] I just noticed the last few responses but wanted to tell you what I did in the last 10 minutes. After looking at the documentation for "enabling query strings", I decided to give that a try. I do have control over the callback url as I described in my last post, so I enabled query strings and changed the callback to: http://www.mysite.com/index.php?c=mycontroller&m=processAuth I changed my processAuth function in my controller to: Code: function processAuth () { It worked. The processAuth function gets called on the callback and the new callback url is: http://www.mysite.com/index.php?c=mycontroller&m=processAuth&auth_token=3c562b119bd387ec194ade6bab9832c4 So now I just need to figure out how to extract the auth_token value from the processAuth() function. I'll go try to figure that one out now. Thanks again for the responses. URI routing question - El Forum - 01-11-2008 [eluser]freshmug[/eluser] I made some changes to solve my problem. Check out: http://ellislab.com/forums/viewthread/68698/ Thanks for your help. |