Example #1
0
 public static function send($status = 200, $body = '', $error = 0, $content_type = 'application/json')
 {
     // set the status
     $status_header = 'HTTP/1.1 ' . $status . ' ' . Response::_getStatusCodeMessage($status);
     header($status_header);
     // and the content type
     header('Content-type: ' . $content_type);
     if ($error != 0 && $body == '') {
         $body = Response::_getErrorCodeMessage($error);
     }
     echo CJSON::encode(array("status" => $status, "text" => Response::_getStatusCodeMessage($status), "body" => $body, "errorCode" => $error));
     Yii::app()->end();
 }
Example #2
0
 public static function send($status = 200, $body = '', $error = 0, $content_type = 'application/json; charset=utf-8')
 {
     // set the status
     $status_header = 'HTTP/1.1 ' . $status . ' ' . Response::_getStatusCodeMessage($status);
     //header($status_header);
     // and the content type
     //$content_type="application/json; charset=utf-8";
     \Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
     $headers = \Yii::$app->response->headers;
     $headers->add('Content-Type', $content_type);
     //header('Content-type: ' . $content_type);
     if ($error != 0 && $body == '') {
         $body = Response::_getErrorCodeMessage($error);
     }
     $response = \yii\helpers\Json::encode(array("status" => $status, "text" => Response::_getStatusCodeMessage($status), "body" => $body, "errorCode" => $error));
     \Yii::info("Response " . $response . ' sent');
     echo $response;
     \Yii::$app->end();
 }