diff --git a/configure/autoloader/autoload.php b/configure/autoloader/autoload.php index e3b6ad8..8d285af 100644 --- a/configure/autoloader/autoload.php +++ b/configure/autoloader/autoload.php @@ -24,6 +24,14 @@ spl_autoload_register(function ($className) { 'Portfolio\\Source\\Design\\Controller\\Contact\\' => __DIR__ . '/../../source/design/controller/contact/', 'Portfolio\\Source\\Design\\Controller\\Contact\\Read\\' => __DIR__ . '/../../source/design/controller/contact/read', + + + 'Portfolio\\Source\\Design\\Controller\\Test\\' => __DIR__ . '/../../source/design/controller/test/', + 'Portfolio\\Source\\Design\\Controller\\Test\\Create\\' => __DIR__ . '/../../source/design/controller/test/create', + 'Portfolio\\Source\\Design\\Controller\\Test\\Read\\' => __DIR__ . '/../../source/design/controller/test/read', + + + 'Portfolio\\Source\\Design\\Controller\\' => __DIR__ . '/../../source/design/controller/', ]; diff --git a/public/index.php b/public/index.php index 6dc1933..eabbbad 100644 --- a/public/index.php +++ b/public/index.php @@ -25,4 +25,11 @@ $router->get('/tech/:id', 'Portfolio\Source\Design\Controller\Tech\Read\Read@rea $router->get('/contact', 'Portfolio\Source\Design\Controller\Contact\Index@index'); $router->get('/contact/:id', 'Portfolio\Source\Design\Controller\Contact\Read\Read@read'); + + +$router->get('/test', 'Portfolio\Source\Design\Controller\Test\Index@index'); +$router->get('/test/:id', 'Portfolio\Source\Design\Controller\Test\Read\Read@read'); + + + $router->run(); \ No newline at end of file diff --git a/source/design/controller/base.php b/source/design/controller/base.php index c83b334..9ca076b 100644 --- a/source/design/controller/base.php +++ b/source/design/controller/base.php @@ -7,6 +7,7 @@ use Portfolio\Configure\Database\Connection; class Base { protected string $layout = 'portfolio/template/base.html'; + protected $databaseConnection; public function __construct(Connection $databaseConnection) { @@ -15,7 +16,6 @@ class Base public function show(string $path, array $params = null): void { - // Conversion du chemin en fichier HTML $viewPath = dirname(__DIR__, 3) . '/template/' . str_replace('.', '/', $path) . '.html'; if (!is_file($viewPath)) { @@ -29,23 +29,25 @@ class Base // Remplacer les variables dynamiques dans la vue if ($params) { foreach ($params as $key => $value) { - $viewContent = str_replace('{{ ' . $key . ' }}', htmlspecialchars($value), $viewContent); + if (is_array($value) || is_object($value)) { + // Affichage propre pour les tableaux/objets + $replacement = '
' . htmlspecialchars(print_r($value, true)) . '
'; + } else { + $replacement = htmlspecialchars((string)$value); + } + $viewContent = str_replace('{{ ' . $key . ' }}', $replacement, $viewContent); } } $layoutPath = dirname(__DIR__, 3) . '/template/base.html'; - // Charger le layout principal if (!file_exists($layoutPath)) { throw new \Exception("Layout introuvable : $layoutPath"); } $layoutContent = file_get_contents($layoutPath); - - // Injecter le contenu de la vue dans le layout $finalHtml = str_replace('{{ content }}', $viewContent, $layoutContent); - // Afficher le rendu final echo $finalHtml; } } \ No newline at end of file diff --git a/source/design/controller/home/index.php b/source/design/controller/home/index.php index 1059fe8..091ac4a 100644 --- a/source/design/controller/home/index.php +++ b/source/design/controller/home/index.php @@ -6,9 +6,9 @@ use Portfolio\Source\Design\Controller\Base; class Index extends Base { - public function index(): void + public function index() { // Affiche la vue portfolio/template/home/index.html dans le layout portfolio/template/base.html - $this->show('home.index'); + return $this->show('home.index'); } } \ No newline at end of file diff --git a/source/design/controller/home/read/read.php b/source/design/controller/home/read/read.php index 358a44f..fc3528a 100644 --- a/source/design/controller/home/read/read.php +++ b/source/design/controller/home/read/read.php @@ -8,15 +8,6 @@ class Read extends Base { public function read(int $id) { - $requestDatabase = $this->databaseConnection->get_pdo()->query('SELECT * FROM Test'); - $test = $requestDatabase->fetchAll(); - foreach ($test as $tests) { - echo $tests->id; - echo " - "; - echo $tests->label; - echo "
"; - } - return $this->show('home.read.read', ['id' => $id]); } diff --git a/source/design/controller/test/index.php b/source/design/controller/test/index.php new file mode 100644 index 0000000..b0f0d6a --- /dev/null +++ b/source/design/controller/test/index.php @@ -0,0 +1,17 @@ +databaseConnection->get_pdo()->query('SELECT * FROM Test ORDER BY id DESC'); + $tests = $requestDatabase->fetchAll(); + + // Affiche la vue portfolio/template/test/index.html dans le layout portfolio/template/base.html + return $this->show('test.index', compact('tests')); + } +} \ No newline at end of file diff --git a/source/design/controller/test/read/read.php b/source/design/controller/test/read/read.php new file mode 100644 index 0000000..08d8548 --- /dev/null +++ b/source/design/controller/test/read/read.php @@ -0,0 +1,22 @@ +databaseConnection->get_pdo()->query('SELECT * FROM Test'); + $test = $requestDatabase->fetchAll(); + foreach ($test as $tests) { + echo $tests->id; + echo " - "; + echo $tests->label; + echo "
"; + } + + return $this->show('test.read.read', ['id' => $id]); + } +} \ No newline at end of file diff --git a/template/home/read/read.html b/template/home/read/read.html index d45cabe..3165be8 100644 --- a/template/home/read/read.html +++ b/template/home/read/read.html @@ -21,6 +21,6 @@
-

Détail de l'article

+

détail home

Identifiant : {{ id }}

\ No newline at end of file diff --git a/template/test/index.html b/template/test/index.html new file mode 100644 index 0000000..27823e4 --- /dev/null +++ b/template/test/index.html @@ -0,0 +1,27 @@ +
+ + + +
+
+

Test

+

Ceci est un test.

+ {{ tests }} +
\ No newline at end of file diff --git a/template/test/read/read.html b/template/test/read/read.html new file mode 100644 index 0000000..e5bc146 --- /dev/null +++ b/template/test/read/read.html @@ -0,0 +1,26 @@ +
+ + + +
+
+

Test

+

Identifiant : {{ id }}

+
\ No newline at end of file