From 1bce7564708840e27bc5dee03fcbf202d1c4bebc Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Wed, 30 Nov 2022 11:03:11 +0100 Subject: [PATCH] Ajoute un lien vers la news --- src/Silex/Gateway/NewsGateway.php | 4 ++-- src/Silex/Model/News.php | 9 ++++++++- views/home.php | 22 ++++++++++++---------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/Silex/Gateway/NewsGateway.php b/src/Silex/Gateway/NewsGateway.php index eff7560..53f7a13 100644 --- a/src/Silex/Gateway/NewsGateway.php +++ b/src/Silex/Gateway/NewsGateway.php @@ -24,7 +24,7 @@ class NewsGateway */ public function getPaginatedRecentNews(int $page = 1, int $limit = 10): array { - $req = $this->pdo->prepare('SELECT title, LEFT(content, ' . self::EXCERPT_LENGTH . ') content, publication_date FROM news ORDER BY publication_date DESC LIMIT :limit OFFSET :offset;'); + $req = $this->pdo->prepare('SELECT id_news, title, LEFT(content, ' . self::EXCERPT_LENGTH . ') content, publication_date FROM news ORDER BY publication_date DESC LIMIT :limit OFFSET :offset;'); $req->bindValue('limit', $limit, PDO::PARAM_INT); $req->bindValue('offset', ($page - 1) * $limit, PDO::PARAM_INT); if (!$req->execute()) { @@ -61,6 +61,6 @@ class NewsGateway private function createNews(array $data): News { - return new News($data['title'], $data['content'], DateTime::createFromFormat('Y-m-d H:i:s', $data['publication_date'])); + return new News(intval($data['id_news']), $data['title'], $data['content'], DateTime::createFromFormat('Y-m-d H:i:s', $data['publication_date'])); } } diff --git a/src/Silex/Model/News.php b/src/Silex/Model/News.php index 72c8329..afc736a 100644 --- a/src/Silex/Model/News.php +++ b/src/Silex/Model/News.php @@ -8,17 +8,24 @@ use DateTime; class News { + private int $id; private string $title; private string $content; private DateTime $publicationDate; - public function __construct(string $title, string $content, DateTime $publicationDate) + public function __construct(int $id, string $title, string $content, DateTime $publicationDate) { + $this->id = $id; $this->title = $title; $this->content = $content; $this->publicationDate = $publicationDate; } + public function getId(): int + { + return $this->id; + } + public function getTitle(): string { return $this->title; diff --git a/views/home.php b/views/home.php index 2f146b1..d9fb0ce 100644 --- a/views/home.php +++ b/views/home.php @@ -1,18 +1,20 @@

Hello world!

-
-
-

- getTitle() ?> -

-
-