-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
index: | ||
uri: / | ||
controller: Controller\HomeController | ||
httpMethod: [GET] | ||
testdb: | ||
uri: /testdb | ||
controller: Controller\DataBaseTestController | ||
httpMethod: [GET] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Controller; | ||
|
||
use Studoo\EduFramework\Core\Controller\ControllerInterface; | ||
use Studoo\EduFramework\Core\Controller\Request; | ||
use Studoo\EduFramework\Core\Service\DatabaseService; | ||
use Studoo\EduFramework\Core\View\TwigCore; | ||
use Twig\Error\LoaderError; | ||
use Twig\Error\RuntimeError; | ||
use Twig\Error\SyntaxError; | ||
|
||
class DataBaseTestController implements ControllerInterface | ||
{ | ||
/** | ||
* @param Request $request Requête HTTP | ||
* @return string|null | ||
* @throws LoaderError | ||
* @throws RuntimeError | ||
* @throws SyntaxError | ||
* @throws \Exception | ||
*/ | ||
public function execute(Request $request): string|null | ||
{ | ||
// Connexion à la base de données | ||
$getConnectDb = DatabaseService::getConnect(); | ||
// Requête SQL | ||
$etudiantStmt = $getConnectDb->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 | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends "base.html.twig" %} | ||
|
||
{% block title %}{{ titre }}{% endblock %} | ||
|
||
{% block content %} | ||
<h1>{{ titre }}</h1> | ||
{% for etudiant in etudiants %} | ||
<p>{{ etudiant.prenom }} {{ etudiant.nom }}</p> | ||
{% endfor %} | ||
{% endblock %} | ||
|