-
Notifications
You must be signed in to change notification settings - Fork 0
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
5 changed files
with
72 additions
and
1 deletion.
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,40 @@ | ||
<?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->query("SELECT * FROM `etudiant`"); | ||
// 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
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,8 @@ | ||
{% extends "base.html.twig" %} | ||
|
||
{% block title %}Error{% endblock %} | ||
|
||
{% block content %} | ||
<h1>Error Default Route</h1> | ||
{% endblock %} | ||
|
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,18 @@ | ||
{% extends "base.html.twig" %} | ||
|
||
{% block title %}{{ titre }}{% endblock %} | ||
|
||
{% block content %} | ||
<h1>{{ titre }}</h1> | ||
{# Parcours de la variable etudiants #} | ||
<h3>Parcours de la variable etudiants</h3> | ||
{% for etudiant in etudiants %} | ||
<p>{{ etudiant.prenom }} {{ etudiant.nom }}</p> | ||
{% endfor %} | ||
|
||
<h3>Affichage Dump pour debug de variable</h3> | ||
{# Test de la variable etudiants #} | ||
{{ dd(etudiants) }} | ||
|
||
{% endblock %} | ||
|