diff options
| author | polo <ordipolo@gmx.fr> | 2025-11-02 20:08:52 +0100 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-11-02 20:08:52 +0100 |
| commit | 28d300b48ded1d472d3593f3afc0c71c4fd2e0aa (patch) | |
| tree | e8c3a19c3d6d45126837275eee412ef44e046f96 /src/model | |
| parent | b9a5dd61e04ba09be0ffba300bd1da49e4de090c (diff) | |
| download | cms-28d300b48ded1d472d3593f3afc0c71c4fd2e0aa.tar.gz cms-28d300b48ded1d472d3593f3afc0c71c4fd2e0aa.tar.bz2 cms-28d300b48ded1d472d3593f3afc0c71c4fd2e0aa.zip | |
blocage suppression dernière page, page par défaut = première entrée du menu et non plus "accueil"
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/Path.php | 23 |
1 files changed, 10 insertions, 13 deletions
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 | |||
| 25 | // produit un tableau de Page en comparant le chemin demandé avec les données dans Menu | 25 | // produit un tableau de Page en comparant le chemin demandé avec les données dans Menu |
| 26 | // succès => une exception est lancée pour sortir des fonctions imbriquées | 26 | // succès => une exception est lancée pour sortir des fonctions imbriquées |
| 27 | // echec => redirection vers la page erreur 404 | 27 | // echec => redirection vers la page erreur 404 |
| 28 | private function findPage(Page|Menu $menu, array $path_array) | 28 | private function findPage(Page|Menu $menu, array $path_array): void |
| 29 | { | 29 | { |
| 30 | // recherche dans les autres pages | 30 | // recherche dans les autres pages |
| 31 | if($menu instanceof Menu){ | 31 | if($menu instanceof Menu){ |
| 32 | foreach($menu->getOtherPages() as $page) | 32 | foreach($menu->getOtherPages() as $page){ |
| 33 | { | 33 | if($path_array[0] === $page->getEndOfPath()){ |
| 34 | if($path_array[0] === $page->getEndOfPath()) | ||
| 35 | { | ||
| 36 | $this->current_page[] = $page; | 34 | $this->current_page[] = $page; |
| 37 | throw new Exception(); | 35 | throw new Exception(); |
| 38 | } | 36 | } |
| 39 | } | 37 | } |
| 40 | } | 38 | } |
| 41 | // recherche dans le menu | 39 | // recherche dans le menu |
| 42 | foreach($menu->getChildren() as $page) | 40 | foreach($menu->getChildren() as $page){ |
| 43 | { | 41 | if($path_array[0] === $page->getEndOfPath()){ |
| 44 | if($path_array[0] === $page->getEndOfPath()) | ||
| 45 | { | ||
| 46 | $this->current_page[] = $page; | 42 | $this->current_page[] = $page; |
| 47 | if(count($path_array) > 1) | 43 | if(count($path_array) > 1){ |
| 48 | { | ||
| 49 | array_shift($path_array); // $this->path_array n'est pas modifié, un tableau PHP est passé à une fonction par copie | 44 | array_shift($path_array); // $this->path_array n'est pas modifié, un tableau PHP est passé à une fonction par copie |
| 50 | $this->findPage($page, $path_array); | 45 | $this->findPage($page, $path_array); |
| 51 | } | 46 | } |
| @@ -54,9 +49,11 @@ class Path extends Page | |||
| 54 | } | 49 | } |
| 55 | } | 50 | } |
| 56 | } | 51 | } |
| 52 | |||
| 57 | // rien trouvé | 53 | // rien trouvé |
| 58 | URL::setPath('erreur404.html'); | 54 | // pas parfait, échoue si le premier enfant de "children" n'est pas au premier niveau |
| 59 | header('Location: '. new URL); | 55 | // est-ce que ça peut arriver? |
| 56 | header('Location: '. new URL(['page' => Model::$menu->getChildren()[0]->getEndOfPath()])); | ||
| 60 | die; | 57 | die; |
| 61 | } | 58 | } |
| 62 | 59 | ||
