简体   繁体   English

Cakephp如何从GET提交中检索数据

[英]Cakephp How to retrieve data from GET submit

I'm passing a search data on method GET like that: 我正在像这样传递关于GET方法的搜索数据:

example.com/posts/?q=foo

I'm trying retrive this data on controller doing this: 我正在尝试在控制器上检索此数据:

$this->params['q'];

but is not working. 但不起作用。

Looks like you're using CakePHP 1.3. 看起来您正在使用CakePHP 1.3。 If the submission was made using Cake's Form Helper, it should be something like.. 如果提交是使用Cake的Form Helper进行的,则应类似..

$this->params['data']['q']

or if you explicitly wrote your own HTML code for the form, 或者,如果您为表单明确编写了自己的HTML代码,

$this->params['url']['q']

CakePHP specifice function for accessing query strings: CakePHP规范函数,用于访问查询字符串:

$this->request->query['q'];

Reference: Link . 参考: 链接

CakePHP has simple helpers that let you access parameters. CakePHP具有简单的帮助程序 ,可让您访问参数。


For GET parameters you can use: 对于GET参数,您可以使用:

/users/search?age=23
$this->request->query['age']; // 23

For POST parameters you can use: 对于POST参数,您可以使用:

$this->request->data('age'); // 23

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM