Affiche un extrait de news sur la page d'accueil
This commit is contained in:
@@ -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()) {
|
||||
|
@@ -1,3 +1,16 @@
|
||||
<?php $params['title'] = 'Home'; ?>
|
||||
<h1>Hello world!</h1>
|
||||
<?= var_dump($params) ?>
|
||||
<?php foreach ($params['news'] as $news) : ?>
|
||||
<div class="card">
|
||||
<header class="card-header">
|
||||
<p class="card-header-title">
|
||||
<?= $news->getTitle() ?>
|
||||
</p>
|
||||
</header>
|
||||
<div class="card-content">
|
||||
<div class="content">
|
||||
<?= $news->getContent() ?>...
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach ?>
|
Reference in New Issue
Block a user