Historisation Exemple
Exemple test historisé
This commit is contained in:
8
blog_mvc/blog.php
Normal file
8
blog_mvc/blog.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
include_once('modele/connexion_sql.php');
|
||||
|
||||
if (!isset($_GET['section']) OR $_GET['section'] == 'index')
|
||||
{
|
||||
include_once('controleur/blog/index.php');
|
||||
}
|
||||
17
blog_mvc/controleur/blog/index.php
Normal file
17
blog_mvc/controleur/blog/index.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
// On demande les 5 derniers billets (mod<6F>le)
|
||||
include_once('modele/blog/get_billets.php');
|
||||
$billets = get_billets(0, 5);
|
||||
|
||||
// On effectue du traitement sur les donn<6E>es (contr<74>leur)
|
||||
// Ici, on doit surtout s<>curiser l'affichage
|
||||
foreach($billets as $cle => $billet)
|
||||
{
|
||||
$billets[$cle]['titre'] = htmlspecialchars($billet['titre']);
|
||||
$billets[$cle]['contenu'] = nl2br(htmlspecialchars($billet['contenu']));
|
||||
}
|
||||
|
||||
// On affiche la page (vue)
|
||||
include_once('vue/blog/index.php');
|
||||
|
||||
16
blog_mvc/modele/blog/get_billets.php
Normal file
16
blog_mvc/modele/blog/get_billets.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
function get_billets($offset, $limit)
|
||||
{
|
||||
global $bdd;
|
||||
$offset = (int) $offset;
|
||||
$limit = (int) $limit;
|
||||
|
||||
$req = $bdd->prepare('SELECT id, titre, contenu, DATE_FORMAT(date_creation, \'%d/%m/%Y <20> %Hh%imin%ss\') AS date_creation_fr FROM billets ORDER BY date_creation DESC LIMIT :offset, :limit');
|
||||
$req->bindParam(':offset', $offset, PDO::PARAM_INT);
|
||||
$req->bindParam(':limit', $limit, PDO::PARAM_INT);
|
||||
$req->execute();
|
||||
$billets = $req->fetchAll();
|
||||
|
||||
|
||||
return $billets;
|
||||
}
|
||||
11
blog_mvc/modele/connexion_sql.php
Normal file
11
blog_mvc/modele/connexion_sql.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
// Connexion <20> la base de donn<6E>es
|
||||
try
|
||||
{
|
||||
$bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '');
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
die('Erreur : '.$e->getMessage());
|
||||
}
|
||||
33
blog_mvc/vue/blog/index.php
Normal file
33
blog_mvc/vue/blog/index.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
|
||||
<head>
|
||||
<title>Mon blog</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
||||
<link href="vue/blog/style.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Mon super blog !</h1>
|
||||
<p>Derniers billets du blog :</p>
|
||||
|
||||
<?php
|
||||
foreach($billets as $billet)
|
||||
{
|
||||
?>
|
||||
<div class="news">
|
||||
<h3>
|
||||
<?php echo $billet['titre']; ?>
|
||||
<em>le <?php echo $billet['date_creation_fr']; ?></em>
|
||||
</h3>
|
||||
|
||||
<p>
|
||||
<?php echo $billet['contenu']; ?>
|
||||
<br />
|
||||
<em><a href="commentaires.php?billet=<?php echo $billet['id']; ?>">Commentaires</a></em>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
27
blog_mvc/vue/blog/style.css
Normal file
27
blog_mvc/vue/blog/style.css
Normal file
@@ -0,0 +1,27 @@
|
||||
h1, h3
|
||||
{
|
||||
text-align:center;
|
||||
}
|
||||
h3
|
||||
{
|
||||
background-color:black;
|
||||
color:white;
|
||||
font-size:0.9em;
|
||||
margin-bottom:0px;
|
||||
}
|
||||
.news p
|
||||
{
|
||||
background-color:#CCCCCC;
|
||||
margin-top:0px;
|
||||
}
|
||||
.news
|
||||
{
|
||||
width:70%;
|
||||
margin:auto;
|
||||
}
|
||||
|
||||
a
|
||||
{
|
||||
text-decoration: none;
|
||||
color: blue;
|
||||
}
|
||||
Reference in New Issue
Block a user