Added charset option for JSON requests.

pull/243/head v1.2.19
Mike Cao 9 years ago
parent 443fa82895
commit b96aaa7967

@ -723,7 +723,7 @@ $body = Flight::request()->getBody();
## JSON Input
If you send request with the type `application/json` and the data `{"id": 123}` it will be available
If you send a request with the type `application/json` and the data `{"id": 123}` it will be available
from the `data` property:
```php

@ -1 +1 @@
1.2.18
1.2.19

@ -448,13 +448,14 @@ class Engine {
* @param mixed $data JSON data
* @param int $code HTTP status code
* @param bool $encode Whether to perform JSON encoding
* @param string $charset Charset
*/
public function _json($data, $code = 200, $encode = true) {
public function _json($data, $code = 200, $encode = true, $charset = 'utf-8') {
$json = ($encode) ? json_encode($data) : $data;
$this->response()
->status($code)
->header('Content-Type', 'application/json')
->header('Content-Type', 'application/json; charset='.$charset)
->write($json)
->send();
}
@ -466,15 +467,16 @@ class Engine {
* @param string $param Query parameter that specifies the callback name.
* @param int $code HTTP status code
* @param bool $encode Whether to perform JSON encoding
* @param string $charset Charset
*/
public function _jsonp($data, $param = 'jsonp', $code = 200, $encode = true) {
public function _jsonp($data, $param = 'jsonp', $code = 200, $encode = true, $charset = 'utf-8') {
$json = ($encode) ? json_encode($data) : $data;
$callback = $this->request()->query[$param];
$this->response()
->status($code)
->header('Content-Type', 'application/javascript')
->header('Content-Type', 'application/javascript; charset='.$charset)
->write($callback.'('.$json.');')
->send();
}

Loading…
Cancel
Save