thinkphp6 API封装接口类restful风格
2022-11-24 11:10:29
163
{{single.collect_count}}

对接口返回的数据进行统一封装,符合restful风格

接口响应数据格式,统一约定为 包含code 、msg、data 三个字段的 json字符串。

在控制器中,定义快速响应数据的方法如下:

放到thinkphp6框架下common.php//公共文件中

function response($code=200, $msg='success', $data=[]){$res = ['code' => $code,'msg' => $msg,'data' => $data];json($res)->send();die;}

thinkphp6 接口响应数据格式 commom.php_code_nutter的博客-CSDN博客

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}