Last active
August 29, 2015 14:12
-
-
Save ebuildy/fe1e708e466dc13dd736 to your computer and use it in GitHub Desktop.
Symfony2 seems not capable to parse Angular $http data. This class overrides default SF2 Request to parse request body sent by Angular then put data in query field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AngularRequest extends \Symfony\Component\HttpFoundation\Request | |
{ | |
/** | |
* Creates a new request with values from PHP's super globals. | |
* | |
* @return Request A new request | |
* | |
* @api | |
*/ | |
public static function createFromGlobals() | |
{ | |
$request = parent::createFromGlobals(); | |
$requestBody = $request->getContent(); | |
if (!empty($requestBody)) | |
{ | |
$requestBodyData = json_decode($requestBody, true); | |
if (!empty($requestBodyData) && is_array($requestBodyData)) | |
{ | |
$request->query->add($requestBodyData); | |
} | |
} | |
return $request; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment