Slim JSON Outputs

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

    [BEFORE]: Content-Type text/html; charset=UTF-8

    Not working with SOAPUI JSON :(

    $this->get('get_all', function ($req, $res, $args) {
        $um = new UserModel();
    
        return $res
           ->withHeader('Content-Type', 'application/json')
           ->getBody()
           ->write(
            json_encode(
                $um->get_all()
            )
        );
    });
    

    [AFTER]: Content-Type application/json;charset=utf-8

    Working with SOAPUI JSON ;)

    $this->get('get_all', function ($req, $res, $args) {
        $um = new UserModel();
    
        return $res
            ->withHeader('Content-type', 'application/json;charset=utf-8')
            ->withJson($um->get_all());
    

提交回复
热议问题