php 在 cakephp 中获取和发布
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9598097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get and post in cakephp
提问by OhDude
In Codeigniter I do this
在 Codeigniter 我这样做
$p=$this->input->post();
to get all objects posted but I don't know if there is something similar in cakephp to get all posted variables from a form ? I am writing a function to get posted password and save it into database in place of the old password recorded there.
获取发布的所有对象,但我不知道 cakephp 中是否有类似的东西可以从表单中获取所有发布的变量?我正在编写一个函数来获取发布的密码并将其保存到数据库中以代替记录在那里的旧密码。
I use native php to get 'posted' variables from a form, (I am not familiar with cakephp form usage) that is why, so instead of using $_POST['sssss'] what should I do now ?
我使用本机 php 从表单中获取“发布”变量,(我不熟悉 cakephp 表单的用法)这就是为什么,所以我现在应该做什么而不是使用 $_POST['sssss'] ?
Thank you for any help.
感谢您的任何帮助。
回答by Bas Tuijnman
$value = $this->request->data('key');
Please for further reference, read the manual. It's so much easier and better for yourself to figure it out by yourself.
如需进一步参考,请阅读手册。对自己来说,自己弄清楚要容易得多,也更好。
http://book.cakephp.org/2.0/en/controllers/request-response.html#accessing-post-data
http://book.cakephp.org/2.0/en/controllers/request-response.html#accessing-post-data
回答by Rajesh Vishwakarma
for the GET method
$this->request->query['category-name'];
and POST method
$this->request->data
http://book.cakephp.org/2.0/en/controllers/request-response.html#accessing-querystring-parameters
http://book.cakephp.org/2.0/en/controllers/request-response.html#accessing-querystring-parameters
回答by Julian Hollmann
The Post data must be in data to show up in $this->request->data.
Post 数据必须在 data 中才能显示在 $this->request->data 中。
Example:
例子:
// input field
<input type="text" name="data[foo]" value="bar" />
// in your controller
debug($this->request->data);
回答by Rinto George
You can check if posted a form by using
您可以使用以下方法检查是否已发布表单
if (!empty($this->data)) {
print_r($this->data);
}
回答by eXi
To check if posted a form, please use:
要检查是否已发布表单,请使用:
if ($this->request->is('post')) {
pr($this->request->data);
}
回答by Sergin
If you want to get a specific field of the table can move so:
如果要获取表的特定字段可以这样移动:
if($this->data["Objetorastreavel"]["id"]){
}
It checks only the ID Objetorestraeval
if you want to pick only one field and not post the whole page.
Objetorestraeval
如果您只想选择一个字段而不是发布整个页面,它只会检查 ID 。
回答by Faisal
You should able to access form post data with:
您应该能够通过以下方式访问表单发布数据:
For CakePHP 2.x
对于 CakePHP 2.x
if ($this->request->is('post')) {
pr($this->request->data);
}
For CakePHP 3.4.x
对于 CakePHP 3.4.x
if ($this->request->is('post')) {
pr($this->request->getData());
}
回答by aryan
You can use following to retrieve post/get data in CakePHP
您可以使用以下方法在 CakePHP 中检索 post/get 数据
For post data:$this->request->data;
对于帖子数据:$this->request->data;
For get data:$this->request->query;
获取数据:$this->request->query;