Structure MVC: double affichage intempestif
Bonjour,
J'ai un empilement de fichiers vues dans une structure MVC. Le contenu de la vue principale est répété deux fois: une première fois en tout début de rendu, une seconde fois à sa place.
Je vous donne le code épuré de mes fichiers dans l'ordre d'apparition dans le code et le rendu (ctrl+U)
Fichier de contrôle 'main.php':
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
| <?php
if ( empty(session_id()) )
session_start();
require_once('../config.php');
require_once('../searchLang.php');
$_SESSION['language'] = $language = selectLanguage();
#...................................... Functions ........................................................
function subscriberHome($language) {
$echo['headTitle'] = getDBText($language,2);
$echo['headKeywords'] = getDBText($language,3);
$echo['headOverview'] = getDBText($language,4);
$echo['errors'] = (empty($_SESSION['errors'])) ? '': displErrors($_SESSION['errors']);
unset($_SESSION['errors']);
require_once('views/menuVUser.php');
$filename = "views/$language/subscriberHome.php";
if (file_exists($filename))
require_once($filename);
}
#.........................................................................................................
$echo['menuV'] = "";
$echo['errors'] = "";
// Select the page to be displayed
(int) $page = $_GET['page'] ?? 0;
switch ($page) {
case 0:
default:
subscriberHome($language);
break;
} |
Fichier menu:
Code:
1 2 3 4 5 6 7 8 9
| <?php ob_start(); ?>
<nav class="mainNav">
<nav>
<!-- ... -->
</nav>
</nav>
<?php $echo['menuV'] = ob_get_clean(); ?> |
Contenu principal 'views/$language/subscriberHome.php':
Code:
1 2 3 4 5 6
| <?php ob_start(); ?>
<h2><?= getDBText($language,45); ?></h2>
<?= $echo['content'] = ob_get_clean(); ?>
<?php require_once('../views/template.php'); ?> |
Template:
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
| <!DOCTYPE html>
<html lang="<?= $language; ?>">
<head>
<!--
<base href="<?= URL_SITE ?>" />
-->
</head>
<body>
<?php require_once('header.php'); ?>
<section>
<div id="left">
<?= $echo['menuV']; ?>
</div>
<article id="right">
<?= $echo['content']; ?>
</article>
</section>
<?php require_once('footer.php'); ?>
</body>
</html> |
Rendu:
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
<script type="text/javascript" src="http://gc.kis.v2.scr.kaspersky-labs.com/FD126C42-EBFA-4E12-B309-BB3FDD723AC1/main.js?attr=0ArFnnVcLOpzycFk0cSvbTt7jl8IoTLMTjNpbHB-AYqCzABdL0j0Odfb1gEH09h4SL1Ug0Lm5vQVoIqB6IFGFw" charset="UTF-8"></script>
<h2>Mon entreprise</h2>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><-Mettre dans ces lignes les renseignements de la balise head du template-></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="author" content="Marc Paris" />
<meta name="copyright" content="Marc Paris" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<base href="http://sirep.proginet.local" />
<link rel="stylesheet" media="all" type="text/css" href="../css/structure.css" />
<link rel="stylesheet" media="all" type="text/css" href="../css/screen.css" />
<link rel="stylesheet" media="print" type="text/css" href="../css/print.css" />
</head>
<body>
<header>
<div class="displTimer">
<span id="timer"></span>
</div>
<div>
<img src="http://sirep.proginet.local/images/logo_sirep.png" alt="logo">
<h1>Votre prospection en ligne</h1>
</div>
</header>
<section>
<div id="left">
<nav class="mainNav">
<nav>
<ul>
<li>Utilisation <ul>
<li><a href="main.php?page=1">Mon entreprise</a></li> <!-- Company home -->
<li><a href="main.php?page=2">Fichier clients</a></li> <!-- Company databank -->
<li><a href="">Chercher un client</a></li> <!-- Find customers -->
<li><a href="">Etats et impressions</a></li> <!-- Lists and prints -->
<li><a href="">Paramètres</a></li> <!-- Settings -->
</ul>
</li>
</ul>
<ul>
<li>Divers <ul>
<li><a href="">Déconnexion</a></li>
<li><a href="">Accueil Sirep</a></li>
<li><a href="">Portail Proginet</a></li>
<li><a href="">Aide</a></li>
</ul>
</li>
</ul>
</nav>
</nav>
</div>
<article id="right">
<h2>Mon entreprise</h2>
</article>
</section>
<footer class="footer">
<!-- ... -->
</footer>
</body>
</html> |
On voit dans le rendu:
- que des lignes ont indument été insérées en début de fichier
- que l'antivirus kaspersky a inséré un script
- que le titre h2 du contenu principal est indument inséré après le script de kaspersky
Si j'ajoute du contenu dans le fichier de contenu principal, il est également répété.