Skip to content

Commit 6a9bf72

Browse files
committed
refactoring
1 parent e4792dd commit 6a9bf72

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

app/controller/UsersController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ public function index()
1414

1515
public function get()
1616
{
17-
$result = $this->Users->find();
17+
$result = $this->Users->findAll();
1818

1919
return ['list' => $this->Helper->toJson($result)];
2020
}
21+
22+
public function add($data)
23+
{
24+
$this->Users->store($data);
25+
}
2126
}

app/model/AppModel.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,5 @@
66

77
class AppModel extends Model
88
{
9-
public function where($dados = null)
10-
{
11-
if (!empty($dados)) {
12-
foreach ($dados as $k => $v) {
13-
if (is_int($v)) {
14-
$where[] = "{$k} = {$v}";
15-
} else {
16-
$where[] = "{$k} = '{$v}'";
17-
}
18-
}
199

20-
return (count($where) > 1) ? implode(' AND ', $where) : ' AND '.$where[0];
21-
}
22-
23-
return $dados;
24-
}
2510
}

app/model/Users.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,25 @@
33
namespace SimpleORM\app\model;
44

55
use SimpleORM\app\model\AppModel;
6+
use SimpleORM\app\model\contracts\UsersInterface;
67

7-
class Users extends AppModel
8+
class Users extends AppModel implements UsersInterface
89
{
910
protected $table = 't_user';
1011
protected $pk = 'user_id';
12+
13+
public function findAll()
14+
{
15+
return $this->find();
16+
}
17+
18+
public function store($data)
19+
{
20+
return $this->save($data);
21+
}
22+
23+
public function remove($id)
24+
{
25+
26+
}
1127
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace SimpleORM\app\model\contracts;
4+
5+
interface UsersInterface
6+
{
7+
public function findAll();
8+
9+
public function store($data);
10+
11+
public function remove($id);
12+
}

0 commit comments

Comments
 (0)