francscafe / json-response
一个简单的类,用于返回带有 HTTP 状态的格式化良好的 JSON 响应
1.1.1
2018-10-24 20:53 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-25 10:26:06 UTC
README
一个简单的类,用于返回带有 HTTP 状态的格式化良好的 JSON 响应
安装
composer require francscafe/json-response
用法
<?php /** * Created by PhpStorm. * User: fcromer * Date: 9/6/18 * Time: 4:57 PM */ require_once __DIR__ ."/vendor/autoload.php"; use Francscafe\ResponseClass\JsonResponse; $student = array( 'name' => 'John Doe', 'course' => 'Software Engineering', 'collections' => ['books' => 'Intro to UML', 'music' => 'rap'] ); new JsonResponse('ok', '', $student);
参数 1(必需)
- success 或 ok - 200 HTTP 状态
- unauthorized - 401 HTTP 状态
- exception - 500 HTTP 状态(内部服务器错误)
参数 2(可选)
字符串 - 返回的消息,如果不可用,则使用空引号
参数 3(可选)
数组 - 数据数组