Ajoute le News Controller
This commit is contained in:
@@ -30,8 +30,25 @@ class NewsGateway
|
||||
}
|
||||
$news = [];
|
||||
while ($data = $req->fetch()) {
|
||||
$news[] = new News($data['title'], $data['content'], DateTime::createFromFormat('Y-m-d H:i:s', $data['publication_date']));
|
||||
$news[] = $this->createNews($data);
|
||||
}
|
||||
return $news;
|
||||
}
|
||||
|
||||
public function getById(int $id): News
|
||||
{
|
||||
$req = $this->pdo->prepare('SELECT * FROM news WHERE id_news=:id;');
|
||||
$req->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
if (!$req->execute()) {
|
||||
return null;
|
||||
}
|
||||
$data = $req->fetch();
|
||||
$news = $this->createNews($data);
|
||||
return $news;
|
||||
}
|
||||
|
||||
private function createNews(array $data): News
|
||||
{
|
||||
return new News($data['title'], $data['content'], DateTime::createFromFormat('Y-m-d H:i:s', $data['publication_date']));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user