This repository was archived by the owner on Jan 29, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,20 @@ response:
6464$response = new JsonResponse($data, 200, [ 'Content-Type' => ['application/hal+json']]);
6565```
6666
67+ Finally, ` JsonResponse ` allows a fourth optional argument, the flags to provide to ` json_encode() ` .
68+ By default, these are set to ` JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT ` (integer
69+ 15), providing [ RFC 4627] ( http://tools.ietf.org/html/rfc4627 ) compliant JSON capable of embedding in
70+ HTML. If you want to specify a different set of flags, use the fourth constructor argument:
71+
72+ ``` php
73+ $response = new JsonResponse(
74+ $data,
75+ 200,
76+ [],
77+ JSON_PRETTY_PRINT | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT
78+ );
79+ ```
80+
6781## Empty Responses
6882
6983Many API actions allow returning empty responses:
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ class JsonResponse extends Response
3737 * - JSON_HEX_TAG
3838 * - JSON_HEX_APOS
3939 * - JSON_HEX_AMP
40- * - JSON_HEX_QUOT options
40+ * - JSON_HEX_QUOT
4141 *
4242 * @param string $data Data to convert to JSON.
4343 * @param int $status Integer status code for the response; 200 by default.
You can’t perform that action at this time.
0 commit comments