I have the following Code:
Controller
class UserController {
public function __construct(userRepository $userRepository) {
$this->userRepository = $userRepository;
}
[...]
Repository
class UserRepository extends AbstractRepository {
public function getTablename() {
return "tbl_users";
}
public function getModel() {
return "administration\\CMR\\UserModel";
}
[...]
AbstractRepository
abstract class AbstractRepository {
protected $pdo;
public function __construct(PDO $pdo) {
$this->pdo = $pdo;
}
abstract public function getTablename();
abstract public function getModel();
function readAll() {
$table = $this->getTablename();
$model = $this->getModel();
$stmt = $this->pdo->query("SELECT * FROM $table");
$res = $stmt->fetchAll(PDO::FETCH_CLASS, $model);
return $res;
}
[...]
My Problem is, that I need the "tbl_users" for one query and a secound table (tbl_locations) for another query. Could anyone please explain how to do this? I think it's unnecessary to write again the same readAll()-Function only with other variable.