[ 139968 ]
[ 38.103.63.16 ]
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">
<div style="font-size: 24px; color: #FFFFFF;">Mon premier site en PHP</div>
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 |