Created
August 2, 2013 12:51
-
-
Save jhuriez/6139643 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Jason { | |
public static function output($status = 'success', $message = '', $data = array()) | |
{ | |
$output = (object) array( | |
'status' => $status, | |
'message' => $message, | |
'data' => $data | |
); | |
// Get the active response object | |
$response = Request::active()->controller_instance->response; | |
// If this is an ajax request, send it as text/json content | |
if (Input::is_ajax()) | |
{ | |
$response->set_header('Content-type', 'application/json'); | |
} | |
return $response->body(json_encode($output)); | |
} | |
public static function error($message = '', $data = array()) | |
{ | |
if (is_object($message) and is_a($message, 'Exception')) | |
{ | |
$data = (object) array( | |
'code'=> $message->getCode(), | |
'file'=> $message->getFile(), | |
'line'=> $message->getLine() | |
); | |
$message = $message->getMessage(); | |
} | |
return static::output('error', $message, $data); | |
} | |
public static function data($data) | |
{ | |
return static::output('success', NULL, $data); | |
} | |
public static function success($message = '') | |
{ | |
return static::output('success', $message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment