Files
webprogrammierung/php/controller/deleteArticle-controller.php
T
NOrtmann1 e0fbd220f0 debugging
2026-06-10 17:23:36 +02:00

39 lines
955 B
PHP

<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
require_once __DIR__ . "/../model/ArticleManager.php";
if ($_SERVER["REQUEST_METHOD"] === "POST") {
if (isset($_POST["id"]) && !empty($_POST["id"])) {
$id = $_POST["id"];
} else {
$_SESSION["message"] = "missing_id";
header("location: ../../index.php?pfad=profile");
exit();
}
if (isset($_SESSION["user"])){
$user = $_SESSION["user"];
} else {
header("location: ../../index.php?pfad=login");
exit();
}
try {
$articleManager = ArticleManager::getInstance();
$articleManager->deleteArticle($id, $user);
} catch (\Exception $e) {
$_SESSION["message"] = $e->getMessage();
header("location: ../../index.php?pfad=profile");
exit();
}
$_SESSION["message"] = "article_deleted";
header("location: ../../index.php?pfad=profile");
exit();
}