fix: Anpassen des Routings für Runden, um URL-Rewriting zu umgehen
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
parent
64f2d752e5
commit
15cce6e697
1 changed files with 23 additions and 21 deletions
|
|
@ -11,7 +11,27 @@ use App\Models\Season;
|
|||
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
|
||||
if ($uri === '/' || $uri === '/index.php') {
|
||||
// Routing basierend auf Query-Parametern, um Probleme mit URL-Rewriting zu umgehen
|
||||
if (($_GET['page'] ?? null) === 'round' && isset($_GET['id'])) {
|
||||
try {
|
||||
$roundId = (int)$_GET['id'];
|
||||
$round = Round::getById($roundId);
|
||||
|
||||
if (!$round) {
|
||||
http_response_code(404);
|
||||
echo "404 Not Found: Runde nicht gefunden.";
|
||||
exit;
|
||||
}
|
||||
|
||||
$games = Game::getGamesByRound($roundId);
|
||||
|
||||
// Lade das View-Template für die Rundenansicht
|
||||
require __DIR__ . '/../src/Views/round.php';
|
||||
} catch (Throwable $e) {
|
||||
http_response_code(500);
|
||||
echo "<p style='color:red;'>Fehler: " . htmlspecialchars($e->getMessage()) . "</p>";
|
||||
}
|
||||
} elseif ($uri === '/' || $uri === '/index.php') {
|
||||
echo "<h1>Willkommen bei Tippspiel 2027</h1>";
|
||||
echo "<p>Dies ist die Nachfolgeversion des alten Tippspiels (Pure PHP Variante).</p>";
|
||||
|
||||
|
|
@ -32,7 +52,8 @@ if ($uri === '/' || $uri === '/index.php') {
|
|||
if ($rounds) {
|
||||
echo "<ul>";
|
||||
foreach ($rounds as $round) {
|
||||
echo '<li><a href="/round/' . htmlspecialchars($round['id']) . '">' . htmlspecialchars($round['name']) . '</a></li>';
|
||||
// Link-Format angepasst, um ohne URL-Rewriting zu funktionieren
|
||||
echo '<li><a href="/index.php?page=round&id=' . htmlspecialchars($round['id']) . '">' . htmlspecialchars($round['name']) . '</a></li>';
|
||||
}
|
||||
echo "</ul>";
|
||||
} else {
|
||||
|
|
@ -75,25 +96,6 @@ if ($uri === '/' || $uri === '/index.php') {
|
|||
} elseif ($uri === '/api/status') {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['status' => 'ok', 'version' => '2027.1']);
|
||||
} elseif (preg_match('/^\/round\/(\d+)$/', $uri, $matches)) {
|
||||
try {
|
||||
$roundId = $matches[1];
|
||||
$round = Round::getById($roundId);
|
||||
|
||||
if (!$round) {
|
||||
http_response_code(404);
|
||||
echo "404 Not Found: Runde nicht gefunden.";
|
||||
exit;
|
||||
}
|
||||
|
||||
$games = Game::getGamesByRound($roundId);
|
||||
|
||||
// Lade das View-Template für die Rundenansicht
|
||||
require __DIR__ . '/../src/Views/round.php';
|
||||
} catch (Throwable $e) {
|
||||
http_response_code(500);
|
||||
echo "<p style='color:red;'>Fehler: " . htmlspecialchars($e->getMessage()) . "</p>";
|
||||
}
|
||||
} else {
|
||||
http_response_code(404);
|
||||
echo "404 Not Found";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue