From 13f3e5de399388e6e4e40f2e28a4059bb47e213e Mon Sep 17 00:00:00 2001 From: bim-g Date: Thu, 25 Apr 2024 22:25:03 +0200 Subject: [PATCH 1/2] [ENH] refactor view to display all data assigned --- src/Core/View.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Core/View.php b/src/Core/View.php index b0f6200..64f7ce0 100644 --- a/src/Core/View.php +++ b/src/Core/View.php @@ -244,6 +244,14 @@ public function assign(string $variable, $value) $this->data[$variable] = $value; } + /** + * List all data assigned before being displayed + * @return array + */ + public function getAssignData(): array + { + return $this->data; + } /** * you should provide the extension of your file, * in another case the file will be missing @@ -273,4 +281,4 @@ public function resetConfig(){ $this->layout = ''; $this->folder_name = ''; } -} \ No newline at end of file +} From 104be58d45dd1cd408d38e317723523dc9b932a6 Mon Sep 17 00:00:00 2001 From: bim-g Date: Thu, 25 Apr 2024 22:33:11 +0200 Subject: [PATCH 2/2] [ENH] make possible to render directly html text content without html page --- composer.lock | 8 +++++--- router/route.php | 4 ++++ src/Core/View.php | 8 ++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/composer.lock b/composer.lock index 54d7f62..9b922a3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1672b0fbbe00eb53e9c4c59acb2706ca", + "content-hash": "80ee11d52c1489f117df24ff04e565e9", "packages": [], "packages-dev": [], "aliases": [], @@ -14,8 +14,10 @@ "prefer-lowest": false, "platform": { "php": ">=7.4", - "ext-mbstring": "*" + "ext-mbstring": "*", + "ext-libxml": "*", + "ext-dom": "*" }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.6.0" } diff --git a/router/route.php b/router/route.php index d382b9d..65567fa 100644 --- a/router/route.php +++ b/router/route.php @@ -9,6 +9,10 @@ $router->get('/', function () { (new View)->display('/home'); }); + +$router->get('/helloworld', function () { + (new View)->renderHTML('

Hello World!

'); +}); $router->get('/home', [\Wepesi\Controller\indexController::class,'home']); // $router->post('/changelang', [indexController::class, 'changeLang']) diff --git a/src/Core/View.php b/src/Core/View.php index 64f7ce0..2573d26 100644 --- a/src/Core/View.php +++ b/src/Core/View.php @@ -183,6 +183,14 @@ protected function renderLayout(string $view) } } + /** + * render html string text + * @param string $html + * @return void + */ + public function renderHTML(string $html) { + print($html); + } /** * @param $html *