Skip to content

Commit

Permalink
add new release v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bfoujols committed Dec 31, 2023
1 parent 416b95a commit 8c876e8
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/Config/routes.yaml
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]
40 changes: 40 additions & 0 deletions app/Controller/DataBaseTestController.php
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,
]
);
}
}
3 changes: 2 additions & 1 deletion app/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class HomeController implements ControllerInterface
*/
public function execute(Request $request): string|null
{
return TwigCore::getEnvironment()->render('home/home.html.twig',
return TwigCore::getEnvironment()->render(
'home/home.html.twig',
[
'titre' => 'Hello World !',
'requete' => $request
Expand Down
8 changes: 8 additions & 0 deletions app/Template/error/http-Default.html.twig
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 %}

18 changes: 18 additions & 0 deletions app/Template/home/db.html.twig
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 %}

0 comments on commit 8c876e8

Please sign in to comment.