From 597103b4e4455fd797e177acb496e88c59f10a18 Mon Sep 17 00:00:00 2001 From: "anthony.richard" Date: Sat, 11 Nov 2023 14:12:40 +0100 Subject: [PATCH] case null renvoie vers home.html + meilleures exceptions (normalement) --- Project/php/controller/AdminController.php | 16 ++++++------ Project/php/controller/FrontController.php | 9 +++---- Project/php/controller/StudentController.php | 27 ++++++++++---------- Project/php/controller/TeacherController.php | 24 ++++++++--------- 4 files changed, 35 insertions(+), 41 deletions(-) diff --git a/Project/php/controller/AdminController.php b/Project/php/controller/AdminController.php index 058e711..d61df18 100755 --- a/Project/php/controller/AdminController.php +++ b/Project/php/controller/AdminController.php @@ -2,9 +2,8 @@ namespace controller; -use gateway\GroupGateway; use model\MdlAdmin; -use model\UserGateway; +use Exception; class AdminController { @@ -17,7 +16,6 @@ class AdminController switch($action) { case 'showAllUsers': - case null: $this->showAllUsers(); break; @@ -61,16 +59,18 @@ class AdminController $this->addUserToGroup(); break; + case null: + echo $twig->render('home.html'); + break; + default: $dVueEreur[] = "Erreur d'appel php"; echo $twig->render('vuephp1.html', ['dVueEreur' => $dVueEreur]); break; } - } catch (\PDOException $e) { - - $dVueEreur[] = 'Erreur inattendue!!! '; - } catch (\Exception $e2) { - $dVueEreur[] = $e2->getMessage()." ".$e2->getFile()." ".$e2->getLine().'Erreur inattendue!!! '; + } + catch (Exception $e) { + $dVueEreur[] = $e->getMessage()." ".$e->getFile()." ".$e->getLine().'Erreur inattendue!!! '; echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); } exit(0); diff --git a/Project/php/controller/FrontController.php b/Project/php/controller/FrontController.php index 7b948c6..6b6e793 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -1,8 +1,7 @@ getMessage()." ".$e2->getFile()." ".$e2->getLine().'Erreur inattendue!!! '; + catch (Exception $e) { + $dVueEreur[] = $e->getMessage()." ".$e->getFile()." ".$e->getLine().'Erreur inattendue!!! '; echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); } } diff --git a/Project/php/controller/StudentController.php b/Project/php/controller/StudentController.php index 088e314..d37169b 100755 --- a/Project/php/controller/StudentController.php +++ b/Project/php/controller/StudentController.php @@ -2,43 +2,42 @@ namespace controller; use model\MdlStudent; -use gateway\UserGateway; -use config\Connection; +use Exception; class StudentController { - public function __construct() { global $twig; - session_start(); - $actionList = ['showVocab', 'getByName']; - $dVueEreur = []; + try { $action = $_REQUEST['action'] ?? null; switch ($action) { case 'allVocab': - case null: $this->affAllVocab(); break; + case 'getByName': $this->getByName($_REQUEST['nom']); break; + + case null: + echo $twig->render('home.html'); + break; + default: $dVueEreur[] = "Erreur d'appel php"; echo $twig->render('vuephp1.html', ['dVueEreur' => $dVueEreur]); break; } - } catch (\PDOException $e) { - $dataVueEreur[] = "Erreur inattendue"; - $twig->render("vuephp1.html", ['dVueErreur' => $dataVueEreur]); - - } catch (Exception $e2) { - $dataVueEreur[] = "Erreur inattendue!!! "; - require($dataVueEreur['erreur']); + } + catch (Exception $e) { + $dVueEreur[] = $e->getMessage()." ".$e->getFile()." ".$e->getLine().'Erreur inattendue!!! '; + echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); } } + public function affAllVocab(): void { global $twig; diff --git a/Project/php/controller/TeacherController.php b/Project/php/controller/TeacherController.php index e2dc9b0..3c700d6 100755 --- a/Project/php/controller/TeacherController.php +++ b/Project/php/controller/TeacherController.php @@ -2,20 +2,18 @@ namespace controller; use model\MdlTeacher; -use gateway\UserGateway; -use config\Connection; +use Exception; + class TeacherController { public function __construct() { global $twig; - session_start(); - $actionList = ['getAllStudent','getAllVocab','getVocabByName','AddVocab', 'DelVocab']; - $dVueEreur = []; + try { $action = $_REQUEST['action'] ?? null; switch ($action) { - case null: + case 'getAllStudent': $this->affAllStudent(); break; @@ -33,19 +31,19 @@ class TeacherController $this->delById($_REQUEST['id']); break;*/ + case null: + echo $twig->render('home.html'); + break; + default: $dVueEreur[] = "Erreur d'appel php"; echo $twig->render('vuephp1.html', ['dVueEreur' => $dVueEreur]); break; } } - catch (\PDOException $e) { - $dataVueEreur[] = "Erreur inattendue"; - $twig->render("vuephp1.html", ['dVueErreur' => $dataVueEreur]); - - } catch (Exception $e2) { - $dataVueEreur[] = "Erreur inattendue!!! "; - require($dataVueEreur['erreur']); + catch (Exception $e) { + $dVueEreur[] = $e->getMessage()." ".$e->getFile()." ".$e->getLine().'Erreur inattendue!!! '; + echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); } } public function affAllStudent(): void