Skip to content

Instantly share code, notes, and snippets.

@naosim
Created January 2, 2017 01:56
Show Gist options
  • Save naosim/fe66c5a731c3481633e7a873c535e898 to your computer and use it in GitHub Desktop.
Save naosim/fe66c5a731c3481633e7a873c535e898 to your computer and use it in GitHub Desktop.
GET and POST in PHP
function get($action) {
try {
sendJsonResponse($action($_GET));
} catch(Exception $e) {
sendJsonResponse([
'result' => [ 'status' => 'ng', 'message' => $e->getMessage() ]
]);
}
}
function post($action) {
try {
sendJsonResponse($action($_POST));
} catch(Exception $e) {
sendJsonResponse([
'result' => [ 'status' => 'ng', 'message' => $e->getMessage() ]
]);
}
}
function getParamOrThrow(array $ary, string $key, Exception $exception) {
if(isset($ary[$key])) {
return $ary[$key];
} else {
throw $exception;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment