From d7ab71841e8d885231b623482fc68feef5673d72 Mon Sep 17 00:00:00 2001 From: Emmanuel ROY Date: Tue, 25 May 2021 16:33:58 +0200 Subject: [PATCH] =?UTF-8?q?update:=20=20-=20am=C3=A9lioration=20mod=C3=A8l?= =?UTF-8?q?e=20objet=20du=20MVC=20=20-=20ajout=20des=20param=C3=A8tres=20e?= =?UTF-8?q?n=20$=5FGET=20provenant=20de=20l'url=20=20-=20ajout=20de=20deux?= =?UTF-8?q?=20pages=20pour=20tester=20tout=20=C3=A7=C3=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/class/Application.php | 13 +++++++-- application/class/Controlleur.php | 15 ++++++++-- application/class/Modele.php | 12 ++++++-- application/class/Url.php | 23 ++++++++------- application/class/Vue.php | 29 ++++++++++++++----- .../include/controlleurs/get-params.php | 6 ++++ application/include/controlleurs/index.php | 4 ++- application/traitements/traitement-get.php | 7 +++++ console/output/.gitignore | 2 ++ 9 files changed, 86 insertions(+), 25 deletions(-) create mode 100644 application/include/controlleurs/get-params.php create mode 100644 application/traitements/traitement-get.php create mode 100644 console/output/.gitignore diff --git a/application/class/Application.php b/application/class/Application.php index d67fa28..10bfe5e 100644 --- a/application/class/Application.php +++ b/application/class/Application.php @@ -1,5 +1,12 @@ controlleur = new Controlleur($this); //si la page n'est un controlleur d'action alors on affiche l'écran if (!$this->url->page['control']) { - print($controlleur->vue->ecran); + print($this->controlleur->vue->ecran); //si on affiche l'écran alors on vide les alertes de la session \MVC\Object\Alert::remove(); } diff --git a/application/class/Controlleur.php b/application/class/Controlleur.php index 7a1caa4..2ab43f1 100644 --- a/application/class/Controlleur.php +++ b/application/class/Controlleur.php @@ -1,5 +1,12 @@ url->page['control']) { $url_params = $application->url->page['params']; + foreach($application->url->page['params'] as $key => $value){ + $_GET[$key] = $value; + $url_params[$key] = $value; + } require TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $application->url->page['name'] . '.php'; //sinon c'est une page MVC normale } else { @@ -46,10 +57,10 @@ class Controlleur // ainsi on instancie la page précédente et le javascript et le css asynchrone \MVC\Object\Session::createAndTestSession(); } - //fixme: doit on passer l'application entière dans la vue ou seulement $application->modele->page ? - $this->vue = new Vue($this); + $this->vue = new Vue($this->modele->page); } } + return $this; } public function callHttpResponse($application) diff --git a/application/class/Modele.php b/application/class/Modele.php index 6cc418f..f1785ee 100644 --- a/application/class/Modele.php +++ b/application/class/Modele.php @@ -1,5 +1,12 @@ page['url_params'] = $base_param['params']; + $this->page['all_params'] = $base_param['params']; //export nom a nom les variable dans la superglobale $_GET foreach($base_param['params'] as $key => $value){ $_GET[$key] = $value; @@ -39,11 +46,12 @@ class Modele } else { $this->page['name'] = $base_param['name']; $this->page['description'] = $base_param['description']; - $this->page['params'] = $base_param['params']; + $this->page['all_params'] = $base_param['params']; //export nom a nom les variable dans la superglobale $_GET foreach($base_param['params'] as $key => $value){ $_GET[$key] = $value; } } + return $this; } } diff --git a/application/class/Url.php b/application/class/Url.php index 8f66ea7..f808d0b 100644 --- a/application/class/Url.php +++ b/application/class/Url.php @@ -1,5 +1,12 @@ registre->getIndex())) { $page['name'] = 'error'; $page['params'] = array(); @@ -67,9 +74,10 @@ class Url return; } else { foreach ($urlParts as $key => $value) { - $values[] = $value; - $keys[] = $key; + $values[] = $value; + $keys[] = $value; } + //$page['params'] = array_combine($keys, $values); $page['params'] = $values; } @@ -236,18 +244,13 @@ class Url } else { $scheme = 'http'; } - $base_url = $scheme . "://" . $url ; + $base_url = $scheme . "://" . $url . "/"; $url = $base_url; }else{ $url = PATH_URL; } - if(str_ends_with($url . "/" . BASE_SERVER_DIRECTORY , '/')){ - return substr($url . "/" . BASE_SERVER_DIRECTORY,0,-1); - }else { - return $url . "/" . BASE_SERVER_DIRECTORY; - } + return $url . BASE_SERVER_DIRECTORY; } - /** * Obtiens le fragment depuis une variable serveur, * ce qui est selon moi possible avec une bonne configuration serveur diff --git a/application/class/Vue.php b/application/class/Vue.php index 66ff082..c31a5e0 100644 --- a/application/class/Vue.php +++ b/application/class/Vue.php @@ -1,5 +1,12 @@ modele->page); + //$templateData = array(); + $url_params = array(); + $templateData = $page_params; + + extract($page_params); + //de base on ajoute les parametres du .model et ceux provenant de l'url + foreach ($page_params['all_params'] as $key => $value) { + //$templateData[$key] = $value; + $_GET[$key] = $value; + $url_params[$key] = $value; + } + if(!isset($engine)){$engine = 'blade';} $flag_exist = false; @@ -50,16 +67,12 @@ class Vue $renderer = new \Windwalker\Renderer\BladeRenderer($paths, array('cache_path' => VIEW_PATH . DIRECTORY_SEPARATOR . "cache")); } - - //de base on ajoute les parametres du .model et ceux provenant de l'url - foreach ($application->modele->page as $key => $value) { - $templateData[$key] = $value; - } //WINWALKER TEMPLATING ENGINE RENDER echo $renderer->render($name, $templateData); } else { include CONTROLLER_PATH . DIRECTORY_SEPARATOR . $name . '.php'; } $this->ecran = ob_get_clean(); + return $this; } } diff --git a/application/include/controlleurs/get-params.php b/application/include/controlleurs/get-params.php new file mode 100644 index 0000000..02532b4 --- /dev/null +++ b/application/include/controlleurs/get-params.php @@ -0,0 +1,6 @@ +'blade',"templating_b"=>'twig',"templating_c"=>'edge'); +$templateData["templating_a"] ='blade'; +$templateData["templating_b"] ='twig'; +$templateData["templating_c"] ='edge'; Logger::addLog('ok', 'Hello world'); diff --git a/application/traitements/traitement-get.php b/application/traitements/traitement-get.php new file mode 100644 index 0000000..99b6d44 --- /dev/null +++ b/application/traitements/traitement-get.php @@ -0,0 +1,7 @@ +