Created
January 2, 2017 01:56
-
-
Save naosim/fe66c5a731c3481633e7a873c535e898 to your computer and use it in GitHub Desktop.
GET and POST in PHP
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
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