34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
|
||
/**
|
||
* Basis für Seiten-Controller. Rendert eine View – optional im gemeinsamen
|
||
* Layout (Startseite/Regeln/Legal) oder als eigenständiges Dokument
|
||
* (Spiel/Login/Profil/Admin, die eigene Nav + noindex mitbringen).
|
||
*/
|
||
abstract class Controller
|
||
{
|
||
/** @param array<string,mixed> $meta */
|
||
protected function view(string $page, array $meta = [], bool $layout = true): void
|
||
{
|
||
$viewFile = BSB_BASE . '/app/Views/pages/' . $page . '.php';
|
||
if (!is_file($viewFile)) {
|
||
http_response_code(500);
|
||
echo 'View fehlt: ' . htmlspecialchars($page, ENT_QUOTES);
|
||
return;
|
||
}
|
||
|
||
if (!$layout) {
|
||
require $viewFile;
|
||
return;
|
||
}
|
||
|
||
// Variablen für app/Views/layout.php
|
||
$title = (string) ($meta['title'] ?? 'Black Sheep Bluff');
|
||
$description = (string) ($meta['description'] ?? '');
|
||
$cssFiles = (array) ($meta['css'] ?? []);
|
||
$jsFiles = (array) ($meta['js'] ?? []);
|
||
$bodyClass = (string) ($meta['bodyClass'] ?? '');
|
||
require BSB_BASE . '/app/Views/layout.php';
|
||
}
|
||
}
|