I'm trying to get the variable of a POST request in a symfony 2.4 controller. I usually have no issues on that but for this one...
this is how I call the controller:
var deferred = $q.defer();
$http({method:'POST',data:{dimensionpassed:dimension},url:Routing.generate('_API_getTree')}).success(function(result){
deferred.resolve(result);
});
return deferred.promise;
Now when I look in the console I can see the post request:
JSON
dimensionpassed
"ChartOfAccounts"
Source
{"dimensionpassed":"ChartOfAccounts"}
And here is the controller:
public function _API_getTreeAction(Request $request)
{
$test = $request->getContent();
var_dump($test);
$test = $request->request->get('dimensionpassed');
var_dump($test);
}
The first var dump gives me "{"dimensionpassed":"ChartOfAccounts"}"
so there is something !
but the second is only "NULL"
what am I doing wrong ?
Apparently, Angularjs $http post variable don't go to the $_POST variable, hence it's impossible to have them in the $request->request->all().
However they appear "raw" as you can have them with this:$request->getContent();
Simply using $myvar = json_decode($request->getContent()) does the trick