Skip to content

Commit d9a9b68

Browse files
committed
完善 Database 关键字属性
1 parent 9fbf2e6 commit d9a9b68

File tree

4 files changed

+150
-91
lines changed

4 files changed

+150
-91
lines changed

.idea/workspace.xml

Lines changed: 56 additions & 45 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: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ class apiController {
99
* @param $id
1010
*/
1111
public function test($id){
12-
// echo $_SERVER['REQUEST_METHOD'];
13-
// 删除条目
14-
$result = Demo::find($id)->delete();
12+
13+
// 测试数据库层封装
14+
$result = Database::table('demo')
15+
->setModel(Demo::class)
16+
->select('title')
17+
->where(["author" => "Rytia"])
18+
->orWhereRaw('content LIKE "%测试%"')
19+
->paginate(5);
20+
1521
print_r($result);
22+
1623
}
1724

18-
// 查询类方法演示
25+
// ORM 查询类方法演示
1926

2027
public function find($id){
2128
// 通过 id 查询数据表
@@ -86,4 +93,18 @@ public function paginate($pageNum){
8693
print_r($test);
8794
}
8895

96+
public function databaseWhere(){
97+
98+
// 数据库层封装演示1
99+
$result = Database::table('demo')
100+
->setModel(Demo::class)
101+
->select('title')
102+
->where(["author" => "Rytia"])
103+
->orWhereRaw('content LIKE "%测试%"')
104+
->paginate(5);
105+
106+
print_r($result);
107+
108+
}
109+
89110
}

App/System/Collection.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public function format($modelClass, $sqlStatementCache = '') {
281281

282282
/**
283283
* 依据字段排序元素
284-
* @param string $field, string $orderBy
284+
* @param string $field, string $method
285285
* @return Collection
286286
* @uses Collection 元素排序,集合中的元素应为 Model 实例,且传入比较所依据的字段
287287
*/
@@ -404,15 +404,15 @@ public function getIterator()
404404
}
405405

406406
/**
407-
* 将集合转换为字符串
407+
* 将 Collection 转换为字符串
408408
* @return string
409409
*/
410410
public function __toString() {
411411
return $this->toJson();
412412
}
413413

414414
/**
415-
* 将实例转换为 JSON 字符串
415+
* 将 Collection 转换为 JSON 字符串
416416
* @return string
417417
*/
418418
public function toJson($option = 0) {
@@ -425,8 +425,11 @@ public function toJson($option = 0) {
425425
},$this->collectionItems),$option);
426426
}
427427

428-
// TODO: toArray()
428+
/**
429+
* 将 Collection 转换为数组
430+
* @return array
431+
*/
429432
public function toArray(){
430-
433+
return $this->collectionItems;
431434
}
432435
}

0 commit comments

Comments
 (0)