Slim JSON Outputs

前端 未结 17 1667
一整个雨季
一整个雨季 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:44

    I think Slim also provides a middleware object which does this automatically so users of that framework doesnt have to write json_decode and encode on every request, its called the Slim_Middleware_ContentType object.

    $app->response()->('application/json');
    $app->add(new Slim_Middleware_ContentType());
    

    it does the decoding for you. the decoding works great.But for encoding the last post is great.

    Thanks, Dharani

提交回复
热议问题