@@ -31,7 +31,7 @@ class Controller extends \CI_Controller
31
31
*/
32
32
protected $ responseFormat = [
33
33
'status_code ' => 'code ' ,
34
- 'status_text ' => 'message ' ,
34
+ 'message ' => 'message ' ,
35
35
'body ' => 'data ' ,
36
36
];
37
37
@@ -146,18 +146,21 @@ public function ajax($resourceID=NULL)
146
146
*
147
147
* @param array|mixed Callback data body, false will remove body key
148
148
* @param bool Enable body format
149
- * @param int Callback status code
150
- * @param string Callback status text
149
+ * @param int HTTP Status Code
150
+ * @param string Callback message
151
151
* @return string Response body data
152
+ *
153
+ * @example
154
+ * json(false, true, 401, 'Login Required', 'Unauthorized');
152
155
*/
153
- protected function json ($ data =[], $ bodyFormat =null , $ statusCode =null , $ statusText =null )
156
+ protected function json ($ data =[], $ bodyFormat =null , $ statusCode =null , $ message =null )
154
157
{
155
158
// Check default Body Format setting if not assigning
156
159
$ bodyFormat = ($ bodyFormat !==null ) ? $ bodyFormat : $ this ->bodyFormat ;
157
160
158
161
if ($ bodyFormat ) {
159
162
// Pack data
160
- $ data = $ this ->_format ($ statusCode , $ statusText , $ data );
163
+ $ data = $ this ->_format ($ statusCode , $ message , $ data );
161
164
} else {
162
165
// JSON standard of RFC4627
163
166
$ data = is_array ($ data ) ? $ data : [$ data ];
@@ -174,19 +177,15 @@ protected function json($data=[], $bodyFormat=null, $statusCode=null, $statusTex
174
177
* @param array|mixed|bool Callback data body, false will remove body key
175
178
* @return array Formated array data
176
179
*/
177
- protected function _format ($ statusCode =null , $ statusText =null , $ body =false )
180
+ protected function _format ($ statusCode =null , $ message =null , $ body =false )
178
181
{
179
182
$ format = [];
180
- // Status Code setting
181
- if ($ statusCode ) {
182
- $ this ->response ->setStatusCode ($ statusCode );
183
- }
184
183
// Status Code field is necessary
185
184
$ format [$ this ->responseFormat ['status_code ' ]] = ($ statusCode )
186
185
?: $ this ->response ->getStatusCode ();
187
- // Status Text field
188
- if ($ statusText ) {
189
- $ format [$ this ->responseFormat ['status_text ' ]] = $ statusText ;
186
+ // Message field
187
+ if ($ message ) {
188
+ $ format [$ this ->responseFormat ['message ' ]] = $ message ;
190
189
}
191
190
// Body field
192
191
if ($ body !== false ) {
0 commit comments