Ajoute un lien vers la news
This commit is contained in:
@@ -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']));
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -1,18 +1,20 @@
|
||||
<?php $params['title'] = 'Home'; ?>
|
||||
<h1>Hello world!</h1>
|
||||
<?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() ?>...
|
||||
<a href="<?= $router->url('news/' . $news->getId()) ?>">
|
||||
<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>
|
||||
</div>
|
||||
</a>
|
||||
<?php endforeach ?>
|
||||
<nav class="pagination" role="navigation" aria-label="pagination">
|
||||
<?php if ($params['page'] > 1) : ?>
|
||||
|
Reference in New Issue
Block a user