在 Symfony2 上获取 POST 请求 [英] Getting POST request on Symfony2
本文介绍了在 Symfony2 上获取 POST 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在寻找这个,任何答案都适合我:
I've been looking for this and any of the answers work for me:
我正在使用它来获取 POST
请求:
I'm using this to get the POST
request:
$request = Request::createFromGlobals();
$order = $request->query->get('Ds_Order');
但 Order 永远不会有值,即使名称是正确的.如果我执行 GET
请求该值存在.
But Order is never has a value, even though the name is correct. If I do a GET
request that value exists.
这是$request的var_dump
This is the var_dump of $request
object(Symfony\Component\HttpFoundation\Request)#841 (18) {
["attributes"]=>
object(Symfony\Component\HttpFoundation\ParameterBag)#838 (1) {
["parameters":protected]=>
array(0) {
}
}
["request"]=>
object(Symfony\Component\HttpFoundation\ParameterBag)#840 (1) {
["parameters":protected]=>
array(15) {
["Ds_Date"]=>
string(10) "10/10/2012"
["Ds_Hour"]=>
string(5) "14:31"
["Ds_Currency"]=>
string(3) "978"
["Ds_Order"]=>
string(4) "0026"
}
}
}
有人知道如何访问发送给我的属性吗?
Does anyone know how to access the attributes that are being sent to me?
谢谢.
推荐答案
要检索您必须使用的 POST 请求参数
To retrieve a POST request parameter you've to use
$order = $request->request->get('Ds_Order');
// retrieve GET variables
$request->query->get('foo');
// retrieve POST variables
$request->request->get('bar', 'default value if bar does not exist');
这篇关于在 Symfony2 上获取 POST 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文