diff --git a/app/Config/routes.yaml b/app/Config/routes.yaml index bd47b26..753453c 100644 --- a/app/Config/routes.yaml +++ b/app/Config/routes.yaml @@ -1,4 +1,8 @@ index: uri: / controller: Controller\HomeController + httpMethod: [GET] +testdb: + uri: /testdb + controller: Controller\DataBaseTestController httpMethod: [GET] \ No newline at end of file diff --git a/app/Controller/DataBaseTestController.php b/app/Controller/DataBaseTestController.php new file mode 100644 index 0000000..0f4a605 --- /dev/null +++ b/app/Controller/DataBaseTestController.php @@ -0,0 +1,41 @@ +prepare("SELECT * FROM `etudiant`"); + // Exécution de la requête + $etudiantStmt->execute(); + // Récupération des données + $etudiants = $etudiantStmt->fetchAll(); + + return TwigCore::getEnvironment()->render('home/db.html.twig', + [ + 'titre' => 'Exemple avec connextion à la base de données', + 'etudiants' => $etudiants + ] + ); + } +} diff --git a/app/Template/home/db.html.twig b/app/Template/home/db.html.twig new file mode 100644 index 0000000..e411d39 --- /dev/null +++ b/app/Template/home/db.html.twig @@ -0,0 +1,11 @@ +{% extends "base.html.twig" %} + +{% block title %}{{ titre }}{% endblock %} + +{% block content %} +

{{ titre }}

+ {% for etudiant in etudiants %} +

{{ etudiant.prenom }} {{ etudiant.nom }}

+ {% endfor %} +{% endblock %} +