You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: App/Models/Json.php
+5-3Lines changed: 5 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,18 @@
5
5
class Json
6
6
{
7
7
// Clean and output the given data as JSON with indentation and Unicode and slashes escaping
8
-
publicfunctionclean(array$data)
8
+
publicfunctionclean(array$data, int$code = 200)
9
9
{
10
+
http_response_code($code); // HTTP Code
10
11
header('Content-type: application/json; charset=utf-8'); // Set the response header to indicate JSON content type
11
12
echojson_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); // Encode the data as JSON with pretty print and Unicode and slashes escaping
12
13
}
13
14
14
15
// Output the given data as JSON without any special formatting
15
-
publicfunctionshow(array$data)
16
+
publicfunctionshow(array$data, int$code = 200)
16
17
{
18
+
http_response_code($code); // HTTP Code
17
19
header('Content-type: application/json; charset=utf-8'); // Set the response header to indicate JSON content type
18
20
echojson_encode($data); // Encode the data as JSON
0 commit comments