Historisation Exemple

Exemple test historisé
This commit is contained in:
2018-10-21 18:37:25 +02:00
commit ba3d8f06f6
153 changed files with 32155 additions and 0 deletions

8
blog_mvc/blog.php Normal file
View 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');
}

View 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');

View 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;
}

View 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());
}

View 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>

View 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;
}