From 28d300b48ded1d472d3593f3afc0c71c4fd2e0aa Mon Sep 17 00:00:00 2001 From: polo Date: Sun, 2 Nov 2025 20:08:52 +0100 Subject: =?UTF-8?q?blocage=20suppression=20derni=C3=A8re=20page,=20page=20?= =?UTF-8?q?par=20d=C3=A9faut=20=3D=20premi=C3=A8re=20entr=C3=A9e=20du=20me?= =?UTF-8?q?nu=20et=20non=20plus=20"accueil"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/Path.php | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/model/Path.php') diff --git a/src/model/Path.php b/src/model/Path.php index 8ef9100..0b4bb67 100644 --- a/src/model/Path.php +++ b/src/model/Path.php @@ -25,27 +25,22 @@ class Path extends Page // produit un tableau de Page en comparant le chemin demandé avec les données dans Menu // succès => une exception est lancée pour sortir des fonctions imbriquées // echec => redirection vers la page erreur 404 - private function findPage(Page|Menu $menu, array $path_array) + private function findPage(Page|Menu $menu, array $path_array): void { // recherche dans les autres pages if($menu instanceof Menu){ - foreach($menu->getOtherPages() as $page) - { - if($path_array[0] === $page->getEndOfPath()) - { + foreach($menu->getOtherPages() as $page){ + if($path_array[0] === $page->getEndOfPath()){ $this->current_page[] = $page; throw new Exception(); } } } // recherche dans le menu - foreach($menu->getChildren() as $page) - { - if($path_array[0] === $page->getEndOfPath()) - { + foreach($menu->getChildren() as $page){ + if($path_array[0] === $page->getEndOfPath()){ $this->current_page[] = $page; - if(count($path_array) > 1) - { + if(count($path_array) > 1){ array_shift($path_array); // $this->path_array n'est pas modifié, un tableau PHP est passé à une fonction par copie $this->findPage($page, $path_array); } @@ -54,9 +49,11 @@ class Path extends Page } } } + // rien trouvé - URL::setPath('erreur404.html'); - header('Location: '. new URL); + // pas parfait, échoue si le premier enfant de "children" n'est pas au premier niveau + // est-ce que ça peut arriver? + header('Location: '. new URL(['page' => Model::$menu->getChildren()[0]->getEndOfPath()])); die; } -- cgit v1.2.3