[ 1 036 256 ]
[ 38.107.191.118 ]
Réalisation du site en PHP (partie 4)Etape 4 - Structure du siteRappelez vous nos découpages, lors de l'étude du projet.
Nous allons utiliser ces zones, pour scinder en plusieurs sections, notre fichier principal index.php. De cette façon, quand votre site deviendra de plus en plus gros en codes et en pages, sa maintenance sera des plus aisé. Pour cela nous utiliserons la fonction PHP include(), cette fonction a pour but d'aller chercher le contenu d'un fichier, et de l'inclure dans la partie dans laquelle la fonction include() à été exécutée. Tout d'abord créer ces fichiers sur la racine de votre site:
Pour le moment ces fichiers sont vides.
<?php
error_reporting(E_ALL ^ E_NOTICE);
$page = $_GET['page'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>Mon premier site en PHP</title>
<meta http-equiv="Content-Style-Type" content="text/css">
</head>
<body style="font-family: Arial, sans-serif;font-size: 12px; color: #000000;">
<table width="600" align="center" valign="top" cellspacing="2" cellpadding="2" border="0">
<tr valign="middle">
<td width="600" height="90" colspan="2" bgcolor="#0068B4">
<!-- Coupez cette partie et collez la dans header.php -->
{noir} <div style="font-size: 24px; color: #FFFFFF;">Mon premier site en PHP</div>{/noir}
</td>
</tr>
<tr valign="top">
<td width="120" height="350" rowspan="2" bgcolor="#606DB2">
<!-- Coupez cette partie et collez la dans menu.php -->
{noir} <div style="font-size: 13px;"><b>MENU :</b><br>
<ul>
<li><a href="index.php?page=accueil"> Accueil</a></li>
<li><a href="index.php?page=rubrique1"> Rubrique 1</a></li>
<li><a href="index.php?page=rubrique2"> Rubrique 2</a></li>
<li><a href="index.php?page=rubrique3"> Rubrique 3</a></li>
<li><a href="index.php?page=rubrique4"> Rubrique 4</a></li>
</ul>
</div>{/noir}
</td>
<td width="480" height="310" bgcolor="#AFD394">
<div>
<?php
if (file_exists("pages/$page.html") == TRUE)
{include("pages/$page.html");}
else
{include("pages/accueil.html");}
?>
</div>
</td>
</tr>
<tr valign="middle">
<td width="480" height="40" bgcolor="#CDBCA3">
<!-- Coupez cette partie et collez la dans footer.php -->
{noir} <div>2005 Copyright by Moi</div>{/noir}
</td>
</tr>
</table>
</body>
</html>
Une fois ces opérations effectuées, nous allons inclure les instructions include() dans notre fichier index.php. Dans le fichier index.php, modifiez ce qui suit :
<?php
error_reporting(E_ALL ^ E_NOTICE);
$page = $_GET['page'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>Mon premier site en PHP</title>
<meta http-equiv="Content-Style-Type" content="text/css">
</head>
<body style="font-family: Arial, sans-serif;font-size: 12px; color: #000000;">
<table width="600" align="center" valign="top" cellspacing="2" cellpadding="2" border="0">
<tr valign="middle">
<td width="600" height="90" colspan="2" bgcolor="#0068B4">
<?php include("/header.php"); // appel du fichier header?>
</td>
</tr>
<tr valign="top">
<td width="120" height="350" rowspan="2" bgcolor="#606DB2">
<?php include("/menu.php"); // appel du fichier menu?>
</td>
<td width="480" height="310" bgcolor="#AFD394">
<div>
<?php
if (file_exists("pages/$page.html") == TRUE)
{include("pages/$page.html");}
else
{include("pages/accueil.html");}
?>
</div>
</td>
</tr>
<tr valign="middle">
<td width="480" height="40" bgcolor="#CDBCA3">
<?php include("/footer.php"); // appel du fichier footer?>
</td>
</tr>
</table>
</body>
</html>
Passons à l'étape suivante Suite du Cours [0] commentaire - Voir/Editer |