Example #1
0
    } catch (ResourceNotFoundException $e) {
        $app->response()->status(404);
    } catch (ResourceNotFoundException $e) {
        $app->response()->status(400);
        $app->response()->header('X-Status-Reason', $e->getMessage());
    }
});
$app->post('/editmember/:id(/)', 'authenticate', function ($id) use($app) {
    try {
        $us = new UsersService();
        $request = $app->request();
        $mediaType = $request->getMediaType();
        $body = $request->getBody();
        $input = json_decode($body);
        $u = (string) $input->userid;
        $id = $us->updateUsers($input, $u);
        echo json_encode($id);
    } catch (Exception $e) {
        throw new Exception($e->getMessage());
    }
});
$app->delete('/delmember/:id(/)', 'authenticate', function ($id) use($app) {
    try {
        $us = new UsersService();
        $request = $app->request();
        $mediaType = $request->getMediaType();
        $body = $request->getBody();
        $input = json_decode($body, TRUE);
        $u = (string) $input['userid'];
        $id = $us->deleteUsers($id, $u);
        echo json_encode($id);
}
if (!empty($input->userid)) {
    $user = $input->userid;
} else {
    // http_response_code(401);
    // throw  new Exception('Error!!! You are not login');
    // echo "Error!!! You not login";
    // exit();
}
switch ($method) {
    case 'PUT':
        try {
            if ($input) {
                if (!empty($request[0])) {
                    $u = new Users();
                    $u->{$rs} = $sv->updateUsers($u, $user);
                    echo json_encode($rs);
                } else {
                    throw new Exception('No Id for Update');
                }
            } else {
                throw new Exception('No data for Update');
            }
        } catch (Exception $e) {
            http_response_code(500);
            echo $e->getMessage();
            //throw new Exception($e->getMessage());
        }
        break;
    case 'POST':
        try {