Skip to content

Commit 57b0d6b

Browse files
committed
basic getById method
Signed-off-by: Derek Smart <derek@grindaga.com>
1 parent d47d9f5 commit 57b0d6b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Model.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ abstract class Model extends PHPRed
55
{
66
public $model;
77
public $table;
8+
public $primaryKey;
89

910
public function __construct(\mysqli $mysqli)
1011
{
1112
parent::__construct($mysqli);
1213
}
1314

14-
public function getAll()
15+
public function getAll() : array
1516
{
1617
$query = "SELECT * FROM $this->table;";
1718
return $this->query($query);
1819
}
20+
21+
public function getById(int $modelId) : array
22+
{
23+
$query = "SELECT * FROM $this->table WHERE $this->primaryKey = $modelId;";
24+
return $this->query($query);
25+
}
1926
}

0 commit comments

Comments
 (0)