create-Article-controller Implementation

This commit is contained in:
NOrtmann1
2026-05-26 17:43:07 +02:00
parent 5bcb64f7f8
commit 8c769ba280
3 changed files with 11 additions and 4 deletions
+8 -2
View File
@@ -1,3 +1,9 @@
<?php
//TODO: implement this.
$db::newArticle($_POST['title'], $_POST['content'], $_POST['author']);
try {
$db = Database::getInstance();
$author = "max.mustermann@web.de"; // wird später aus session bezogen.
$db->newArticle($_POST['post-title'], $_POST['post-content'], $author);
} catch (PDOException $e) {
//TODO: Exception werfen, wenn das Erstellen des neuen Artikels nicht geklappt hat.
}
+1
View File
@@ -2,6 +2,7 @@
/*
* Die Klasse dient als Brücke zwischen der Implementierung des DatenbankDAO und der Geschäftslogik.
* Hier kann später die FileDatabase durch die SQL_Database ausgetauscht werden.
* @author Niklas Ortmann
*/
class Database
{
+2 -2
View File
@@ -42,8 +42,8 @@ class FileDatabase implements databaseDAO {
$newData = fopen("articles.txt", "xb");
fclose($newData);
}
$previousData = file_get_contents("gaestebuch.txt");
if (file_put_contents("gaestebuch.txt", "$newData\n$previousData")) {
$previousData = file_get_contents("articles.txt");
if (file_put_contents("articles.txt", "$newData\n$previousData")) {
// TODO: Vernünftige Rückmeldung implementieren.
echo "Artikel erfolgreich gespeichert!";
} else {