Slim JSON Outputs

前端 未结 17 1668
一整个雨季
一整个雨季 2021-01-30 09:00

I am using the Slim framework with PHP to create a RESTful API for my app. However, I assumed that the framework would have some way of creating easier JSON outputs rather than

17条回答
  •  无人及你
    2021-01-30 09:47

    You can use in slim3, Slim’s Response object custom method withJson($data, $status, $encodingOptions)

    $app->get('/hello/{name}', function ($request, $response, $args) {
        $data['msg']='Hello '.$request->getAttribute('name');
        $newResponse = $response->withJson($data);
    });
    

    For more information read here.

提交回复
热议问题