Skip to content

Commit 62d237f

Browse files
committed
完善 Response
1 parent db25013 commit 62d237f

File tree

4 files changed

+221
-66
lines changed

4 files changed

+221
-66
lines changed

.idea/workspace.xml

Lines changed: 60 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

App/Controller/apiController.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
class apiController extends Controller {
99

1010
public function testGet($id){
11-
header("X-Powered-By: PHP-QuickORM");
12-
return $this->response()->json(Demo::find($id));
11+
$data = Demo::find($id);
12+
return $this->response();
1313
}
1414

1515
// ORM 查询类方法演示
@@ -107,4 +107,34 @@ public function databaseOnGet(){
107107
dd($result);
108108

109109
}
110+
111+
public function responseDemoGet($id){
112+
// 响应演示
113+
114+
$data = Demo::find($id);
115+
116+
// 直接返回 JSON
117+
$this->response()->json($data, '200');
118+
119+
// 返回请求标准 JSON 对象
120+
$this->response()->dataEncode($data, '200', '0', '');
121+
122+
// 返回请求标准 JSON 对象
123+
$this->response($data, '200', '0', '');
124+
125+
// 标准 JSON 对象示例
126+
// {
127+
// "errcode": "0",
128+
// "errmsg": "",
129+
// "data": {
130+
// "id": "2",
131+
// "title": "还是标题",
132+
// "content": "这是无敌的测试",
133+
// "author": "Rytia",
134+
// "created_at": "0000-00-00 00:00:00",
135+
// "updated_at": "0000-00-00 00:00:00"
136+
// }
137+
// }
138+
139+
}
110140
}

App/System/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function response($data = null, $statusCode = 200, $errcode = 0, $errmsg
1818
}
1919
}
2020

21-
public function request($field){
21+
public function request($field = null){
2222
if(is_null($field)){
2323
return $this->request;
2424
} else {

0 commit comments

Comments
 (0)