Files
webprogrammierung/php/controller/search-results-controller.php
T
2026-06-02 13:57:30 +02:00

46 lines
1.6 KiB
PHP

<?php
//session_start();
//require_once '/../model/LocalArticleManager.php';
//require_once '/../model/ArticleManager.php';
//test
$modelPath1 = dirname(__DIR__, 2) . '/model/LocalArticleManager.php';
$modelPath2 = dirname(__DIR__, 2) . '/model/ArticleManager.php';
if (file_exists($modelPath1) && file_exists($modelPath2)) {
include_once $modelPath1;
include_once $modelPath2;
} else {
// Falls die Pfade falsch berechnet wurden, stürzt die Seite nicht ab, sondern zeigt das an:
echo "<div style='background: #ffedd5; color: #9a3412; padding: 15px; border: 2px solid #f97316; font-family: Arial;'>";
echo "<strong>Controller-Fehler:</strong> Die Model-Dateien wurden nicht gefunden.<br>";
echo "Gesuchter Pfad 1: <code>" . htmlspecialchars($modelPath1) . "</code><br>";
echo "Gesuchter Pfad 2: <code>" . htmlspecialchars($modelPath2) . "</code>";
echo "</div>";
}
if ($_SERVER["REQUEST_METHOD"] === "GET" && isset($_GET["q"])) {
$search = trim($_GET["q"]);
if (empty($search)) {
$_SESSION["search_results"] = [];
$_SESSION["search_query"] = "";
$_SESSION["message"] = "missing_parameters";
} else {
try {
$articleManager = ArticleManager::getInstance();
$results = $articleManager->search($search);
$_SESSION["search_results"] = $results;
$_SESSION["search_query"] = $search;
$_SESSION["message"] = "new_search_results";
} catch (Exception $e){
$_SESSION["message"] = "internal_error";
}
}
}
?>