first commit
This commit is contained in:
13
public/404.php
Normal file
13
public/404.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
require '../includes/header.php';
|
||||
?>
|
||||
|
||||
<main>
|
||||
<h2>Erreur 404</h2>
|
||||
<p>La page que vous recherchez n’existe pas.</p>
|
||||
<p><a href="index.php">Retour à l’accueil</a></p>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
require '../includes/footer.php';
|
||||
?>
|
||||
28
public/article.php
Normal file
28
public/article.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
require '../includes/header.php';
|
||||
require '../includes/db.php';
|
||||
|
||||
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
|
||||
$id = $_GET['id'];
|
||||
|
||||
$sql = "SELECT * FROM articles WHERE id = :id";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$article = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($article) {
|
||||
echo "<main>";
|
||||
echo "<h2>" . htmlspecialchars($article['titre']) . "</h2>";
|
||||
echo "<p><em>Publié le " . htmlspecialchars($article['date_creation']) . "</em></p>";
|
||||
echo "<div>" . nl2br(htmlspecialchars($article['contenu'])) . "</div>";
|
||||
echo "</main>";
|
||||
} else {
|
||||
require '404.php';
|
||||
}
|
||||
} else {
|
||||
require '404.php';
|
||||
}
|
||||
|
||||
require '../includes/footer.php';
|
||||
?>
|
||||
32
public/index.php
Normal file
32
public/index.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
include 'includes/header.php';
|
||||
|
||||
include 'includes/db.php';
|
||||
?>
|
||||
|
||||
<main>
|
||||
<h2>Derniers articles</h2>
|
||||
|
||||
<?php
|
||||
$sql = "SELECT * FROM articles ORDER BY date_creation DESC LIMIT 10";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
$articles = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($articles) {
|
||||
foreach ($articles as $article) {
|
||||
echo '<article>';
|
||||
echo '<h3>' . htmlspecialchars($article['titre']) . '</h3>';
|
||||
echo '<p>' . substr(htmlspecialchars($article['contenu']), 0, 100) . '...</p>';
|
||||
echo '<a href="article.php?id=' . $article['id'] . '">Lire la suite</a>';
|
||||
echo '</article><hr>';
|
||||
}
|
||||
} else {
|
||||
echo "<p>Aucun article publié pour le moment.</p>";
|
||||
}
|
||||
?>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
include 'includes/footer.php';
|
||||
?>
|
||||
Reference in New Issue
Block a user