views:

1307

answers:

5

How does cakephp handle a get request? For instance, how would it handle a request like this... http://us.mc01g.mail.yahoo.com/mc/welcome?.gx=1&.rand=9553121_pg=showFolder&fid=Inbox&order=down&tt=1732&pSize=20&.rand=425311406&.jsrand=3

Would "mc" be the controller and "welcome" be the action? How is the rest of the information handled?

+2  A: 

CakePHP uses routes to determine this. By default, the routes work as you described. The remainder after the '?' is the querystring and it can be found in $this->params['url'] in the controller, parsed into an associative array.

spoulson
+5  A: 

Also note that you could use named parameters as of Cake 1.2. Named parameters are in key:value order, so the url http://somesite.com/controller/action/key1:value1/key2:value2 would give a a $this->params['named'] array( 'key1' => 'value1', 'key2' => 'value2' ) from within any controller.

If you use a CNN.com style GET request (http://www.cnn.com/2009/SHOWBIZ/books/04/27/ayn.rand.atlas.shrugged/index.html), the parameters are in order of appearance (2009, SHOWBIZ, books, etc.) in the $this->params['pass'] array, indexed starting at 0.

I strongly recommend named paramters, as you can later add features by passing get params, without having to worry about the order. I believe you can also change the named parameter separation key (by default, it's ':').

So it's a slightly different paradigm than the "traditional" GET parameters (page.php?key1=value1&key2=value2). However, you could easily add some logic in the application to automatically parse traditional parameters into an array by tying into how the application parses requests.

Travis Leleu
A: 

It doesn't really use the get in the typical since.

if it was passed that long crazy string, nothing would happen. It expects data in this format: site.com/controller/action/var1/var2/var....

SeanDowney
A: 

Can someone clarify the correct answer? It appears to me that spoulson's and SeanDowney's statements are contradicting each other?

Would someone be able to use the newest version of CakePHP and get the following url to work:

http://www.domain.com/index.php/oauth/authorize?oauth_version=1.0&oauth_nonce=c255c8fdd41bd3096e0c3bf0172b7b5a&oauth_timestamp=1249169700&oauth_consumer_key=8a001709e6552888230f88013f23d5d004a7445d0&oauth_signature_method=HMAC-SHA1&oauth_signature=0bj5O1M67vCuvpbkXsh7CqMOzD0%3D

oauth being the controller and authorize being a method AS WELL as it being able to accept the GET request at the end?

A: 

Since I found this while searching for it, even though it's a little old, others might be able to see this. $this->params['url'] holds GET information. I have tested it and it does work. The page in the Cakephp book for it is http://book.cakephp.org/view/55/The-Parameters-Attribute-params under the 'url' section. It even gives an example very similar to the one in the original question here. This also works in CakePHP 1.3 which is what I'm running.

LucasHammer