News-Bearbeitung gefixt: Feldnamen im Model an Controller & Formular angepasst, keine Notices mehr beim Editieren.
This commit is contained in:
@@ -55,19 +55,44 @@ class NewsController {
|
||||
}
|
||||
|
||||
public function editNewsForm() {
|
||||
$id = $_GET['newsid'];
|
||||
$news = $this->model->getNewsById($id);
|
||||
$this->view->setVars(['news' => $news]);
|
||||
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
|
||||
header('Location: index.php?controller=News&do=showNews');
|
||||
exit;
|
||||
}
|
||||
$id = $_GET['id'] ?? null;
|
||||
if ($id) {
|
||||
$news = $this->model->getNewsById($id);
|
||||
$validData = [
|
||||
'name' => $news['name'] ?? '',
|
||||
'description' => $news['description'] ?? '',
|
||||
'date' => $news['date'] ?? date('Y-m-d'),
|
||||
];
|
||||
$this->view->setVars(['validData' => $validData, 'id' => $id, 'errors' => []]);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateNews() {
|
||||
$id = $_POST['newsid'] ?? null;
|
||||
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
|
||||
header('Location: index.php?controller=News&do=showNews');
|
||||
exit;
|
||||
}
|
||||
$id = $_POST['id'] ?? null;
|
||||
$data = [
|
||||
'name' => $_POST['name'],
|
||||
'beschreibung' => $_POST['beschreibung'],
|
||||
'datum' => $_POST['datum'],
|
||||
'name' => $_POST['name'] ?? '',
|
||||
'description' => $_POST['description'] ?? '',
|
||||
'date' => $_POST['date'] ?? date('Y-m-d'),
|
||||
];
|
||||
$errors = [];
|
||||
if (empty($data['name']) || empty($data['description']) || empty($data['date'])) {
|
||||
$errors['news'] = 'Bitte alle Felder ausfüllen.';
|
||||
}
|
||||
if (!empty($errors)) {
|
||||
$this->view->setVars(['errors' => $errors, 'validData' => $data, 'id' => $id]);
|
||||
$this->view->setDoMethodName('editNewsForm');
|
||||
return;
|
||||
}
|
||||
$this->model->updateNews($id, $data);
|
||||
$this->view->setDoMethodName('showEditSuccess');
|
||||
}
|
||||
|
||||
public function deleteNews() {
|
||||
|
Reference in New Issue
Block a user