1 | <?php |
||
7 | class DemoModel extends Model |
||
8 | { |
||
9 | const TABLE = 'hello'; |
||
10 | const LIMIT = '15'; |
||
11 | |||
12 | public function select($page = 1) |
||
13 | { |
||
14 | $offset = ($page - 1) * static::LIMIT; |
||
15 | |||
16 | return $this->db->select(static::TABLE, '*', [ |
||
17 | 'LIMIT' => [$offset, static::LIMIT], |
||
18 | ]); |
||
19 | } |
||
20 | |||
21 | public function find($id) |
||
22 | { |
||
23 | return $this->db->get(static::TABLE, '*', [ |
||
24 | 'OR' => [ |
||
25 | 'id' => $id, |
||
26 | ], |
||
27 | ]); |
||
28 | } |
||
29 | |||
30 | public function patch($id, array $data) |
||
31 | { |
||
32 | $affected = $this->db->update(static::TABLE, $data, [ |
||
33 | 'OR' => [ |
||
34 | 'id' => $id, |
||
35 | ], |
||
36 | ]); |
||
37 | |||
38 | return $this->find($id); |
||
39 | } |
||
40 | |||
41 | public function create(array $data) |
||
42 | { |
||
43 | $id = $this->db->insert(static::TABLE, $data); |
||
44 | |||
45 | return $this->find($id); |
||
46 | } |
||
47 | |||
48 | public function deleteUser($id) |
||
49 | { |
||
50 | return $this->db->delete(static::TABLE, [ |
||
51 | 'id' => $id, |
||
52 | ]); |
||
53 | } |
||
54 | } |
||
55 |