cakephp and get requests

cakephp and get requests

秋意浓 发布于 2021-11-27 字数 589 浏览 764 回复 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?

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

吃→可爱长大的 2022-06-07 5 楼

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?

云柯 2022-06-07 4 楼

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....

海拔太高太耀眼 2022-06-07 3 楼

Since I found this while searching for it, even though it's a little old.

$this->params['url']

holds GET information.

I have tested but it does work. The page in the Cakephp book for it is this link 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.

浴红衣 2022-06-07 2 楼

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.

月寒剑心 2022-06-07 1 楼

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.