[Blog] Modèle Vue Contrôle erreur d'affichage php
Bonjour à tous,
Je veux créer un blog en php tout en respectant le MVC ( Modèle Vue Contrôleur) que je teste via Easyphp. Toutefois après avoir lancé "Vue" le message d'erreur suivant s'affiche :
Citation:
Notice: Undefined variable: billets in C:\Program Files\EasyPHP-5.3.6.0\www\vue\blog\index.php on line 15
Warning: Invalid argument supplied for foreach() in C:\Program Files\EasyPHP-5.3.6.0\www\vue\blog\index.php on line 15
J'ai posté sur divers sites des demandes d'aide mais malgré l'apport des internautes passionnés rien n'y fait. Pourriez-vous m'aidez s'il vous plaît. Je vous mets ci-dessous chacun de mes fichiers.php a savoir modèle/vue/contrôleur. Merci beaucoup.
Fichier modèle
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <?php
function get_billets($offset,$limit)
{
global $bdd;
$offset=(int)$offset;
$limit=(int)$limit;
$req=$bdd->prepare('SELECT id, image, categorie, titre, contenu, auteur, DATE_FORMAT(date_creation,\'%d/%m/%Y à %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;
} |
Fichier vue
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| <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></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></h1>
<?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> |
Fichier contrôleur
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <?php
//on demande les cinq derniers billets(modèle)
include_once('modele/blog/get_billets.php');
$billets=get_billets(0,5);
//On effectue du traitement sur les données (contrôleur)
//Ici on doit surtout sécuriser l'affichage
foreach($billets as $billet)
{
$billet['titre']=htmlspecialchars($billet['titre']);
$billet['contenu']=n12br(htmlspecialchars($billet['contenu']));
}
//On affiche la page (vue)
include_once('vue/blog/index.php'); |