From cd27eea76e1e6762a8082ec9de983c9d8655d484 Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Tue, 22 Nov 2022 09:40:36 +0100 Subject: [PATCH] Affiche un extrait de news sur la page d'accueil --- src/Silex/Gateway/NewsGateway.php | 4 +++- views/home.php | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Silex/Gateway/NewsGateway.php b/src/Silex/Gateway/NewsGateway.php index 0c2c3af..b7329a7 100644 --- a/src/Silex/Gateway/NewsGateway.php +++ b/src/Silex/Gateway/NewsGateway.php @@ -10,6 +10,8 @@ use Silex\Model\News; class NewsGateway { + private const EXCERPT_LENGTH = 180; + private PDO $pdo; public function __construct(PDO $pdo) @@ -22,7 +24,7 @@ class NewsGateway */ public function getPaginatedRecentNews(int $page = 1, int $limit = 10): array { - $req = $this->pdo->prepare('SELECT * FROM news ORDER BY publication_date DESC LIMIT :limit OFFSET :offset;'); + $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->bindValue('limit', $limit, PDO::PARAM_INT); $req->bindValue('offset', ($page - 1) * $limit, PDO::PARAM_INT); if (!$req->execute()) { diff --git a/views/home.php b/views/home.php index 7d19228..6fb7fa9 100644 --- a/views/home.php +++ b/views/home.php @@ -1,3 +1,16 @@

Hello world!

- \ No newline at end of file + +
+
+

+ getTitle() ?> +

+
+
+
+ getContent() ?>... +
+
+
+ \ No newline at end of file