premier commit
This commit is contained in:
16
appli/biblio.php
Normal file
16
appli/biblio.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// biblio.php
|
||||
/* récupérer le tableau des données */
|
||||
require 'modele/data.php';
|
||||
$donnees = getData();
|
||||
/* inclure l'autoloader */
|
||||
require_once 'vendor/autoload.php';
|
||||
/* templates chargés à partir du système de fichiers (répertoire vue) */
|
||||
$loader = new Twig\Loader\FilesystemLoader('vue');
|
||||
/* options : prod = cache dans le répertoire cache, dev = pas de cache */
|
||||
$options_prod = array('cache' => 'cache', 'autoescape' => true);
|
||||
$options_dev = array('cache' => false, 'autoescape' => true);
|
||||
/* stocker la configuration */
|
||||
$twig = new Twig\Environment($loader);
|
||||
/* charger+compiler le template, exécuter, envoyer le résultat au navigateur */
|
||||
echo $twig->render('biblio.twig', $donnees);
|
||||
19
appli/modele/data.php
Normal file
19
appli/modele/data.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// data.php
|
||||
function getData()
|
||||
{
|
||||
// tableau associatif des données
|
||||
$data = array(
|
||||
'titre_doc' => 'Bibliotheque',
|
||||
'titre_page' => 'Liste des livres',
|
||||
'date' => date("d/m/Y"),
|
||||
// pour simplifier l'exemple, les données sont définies
|
||||
// statiquement (généralement elles sont extraites d'une BD)
|
||||
'biblio' => array(
|
||||
array('titre' => 'N ou M', 'nom' => 'Christie', 'prenom' => 'Agatha'),
|
||||
array('titre' => '1984', 'nom' => 'Orwell', 'prenom' => 'George'),
|
||||
array('titre' => 'Dune', 'nom' => 'Herbert', 'prenom' => 'Frank')
|
||||
)
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
34
appli/vue/biblio.twig
Normal file
34
appli/vue/biblio.twig
Normal file
@@ -0,0 +1,34 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>{{ titre_doc }}</title>
|
||||
<meta charset='UTF-8'>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>{{ titre_page }} - {{ date }}</h1>
|
||||
{% if biblio is not empty %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Titre</th>
|
||||
<th>Auteur</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{# afficher les titres et noms des livres #}
|
||||
{% for item in biblio|sort %}
|
||||
<tr>
|
||||
<td>{{ item.titre }}</td>
|
||||
<td>{{ item.nom|capitalize }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
Aucun livre dans la bibliothèque.
|
||||
{% endif %}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user