Skip to content

Commit

Permalink
add rest style to respond
Browse files Browse the repository at this point in the history
  • Loading branch information
ronalfei committed Nov 5, 2013
1 parent d5a4189 commit fd47432
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions lib/core/codeant.class.php
Expand Up @@ -70,14 +70,7 @@ public function display()
$this->tpl->display($tpl);
$this->debug();
}
public function response($data, $status)
{
$response['result'] = $data;
$response['status'] = $status;
$response_json = json_encode($response);
header('Content-Type:application/json; Charset=utf-8');
echo $response_json;
}

private function setController($controller)
{
$this->controller = $controller;
Expand Down Expand Up @@ -130,6 +123,32 @@ public function run()
}

}


public function response($code, $status, $data)
{
json_response($code, $status, $data);
}

public function json_response($code, $status, $data)
{
$response['result'] = $data;
$response['code'] = $code;
$response['status'] = $status;
$response_json = json_encode($response);
header('Content-Type:application/json; Charset=utf-8');
echo $response_json;
}

public function rest_response($code, $status, $data)
{
$response['result'] = $data;
$response['status'] = $status;
$response_json = json_encode($response);
header('Content-Type:application/json; Charset=utf-8');
header("Status: {$code}");
echo $response_json;
}

}

Expand Down

0 comments on commit fd47432

Please sign in to comment.