JSON request input is now stored in the data property.

pull/126/head
Mike Cao 11 years ago
parent da40e03eb4
commit 81041d418b

@ -673,12 +673,11 @@ ip - IP address of the client
ajax - Whether the request is an AJAX request
scheme - The server protocol (http, https)
user_agent - Browser information
body - Raw data from the request body
type - The content type
length - The content length
query - Query string parameters
data - Post parameters
cookies - Cookie parameters
data - Post data or JSON data
cookies - Cookie data
files - Uploaded files
secure - Whether the connection is secure
accept - HTTP accept parameters
@ -700,6 +699,23 @@ Or you can do:
$id = Flight::request()->query->id;
```
## RAW Request Body
To get the raw HTTP request body, for example when dealing with PUT requests, you can do:
```php
$body = Flight::request()->getBody();
```
## JSON Input
If you send request with the type `application/json` and the data `{"id": 123}` it will be availabe
from the `data` property:
```php
$id = Flight::request()->data->id;
```
# HTTP Caching
Flight provides built-in support for HTTP level caching. If the caching condition

@ -1 +1 @@
1.1.10
1.1.11

@ -93,11 +93,6 @@ class Request {
*/
public $data;
/**
* @var \flight\util\Collection JSON decoded body
*/
public $json;
/**
* @var \flight\util\Collection Cookie parameters
*/
@ -146,7 +141,6 @@ class Request {
'data' => new Collection($_POST),
'cookies' => new Collection($_COOKIE),
'files' => new Collection($_FILES),
'json' => new Collection(),
'secure' => self::getVar('HTTPS', 'off') != 'off',
'accept' => self::getVar('HTTP_ACCEPT'),
'proxy_ip' => self::getProxyIpAddress()
@ -186,9 +180,11 @@ class Request {
// Check for JSON input
if (strpos($this->type, 'application/json') === 0) {
$body = $this->getBody();
if ($body != '') {
$this->json->setData(json_decode($body, true));
$data = json_decode($body, true);
if ($data != null) {
$this->data->setData($data);
}
}
}
}

Loading…
Cancel
Save