Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting POST request on Symfony2

Tags:

symfony

I've been looking for this and any of the answers work for me:

I'm using this to get the POST request:

$request = Request::createFromGlobals();
$order = $request->query->get('Ds_Order');

But Order is never has a value, even though the name is correct. If I do a GET request that value exists.

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?

Thanks.

like image 794
subharb Avatar asked Oct 10 '12 12:10

subharb


1 Answers

To retrieve a POST request parameter you've to use

$order = $request->request->get('Ds_Order');

Read Requests and Responses in Symfony

// retrieve GET variables 
$request->query->get('foo');
// retrieve POST variables
$request->request->get('bar', 'default value if bar does not exist');
like image 86
Ahmed Siouani Avatar answered Sep 17 '22 13:09

Ahmed Siouani