44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Portfolio\Source\Design\Controller;
|
|
|
|
class Base
|
|
{
|
|
protected string $layout = 'portfolio/template/base.html';
|
|
|
|
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)) {
|
|
echo "Vue introuvable : $viewPath<br>";
|
|
print_r(scandir(dirname($viewPath)));
|
|
exit;
|
|
}
|
|
|
|
$viewContent = file_get_contents($viewPath);
|
|
|
|
// Remplacer les variables dynamiques dans la vue
|
|
if ($params) {
|
|
foreach ($params as $key => $value) {
|
|
$viewContent = str_replace('{{ ' . $key . ' }}', htmlspecialchars($value), $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;
|
|
}
|
|
} |