This commit is contained in:
Samuel Wolff 2024-01-17 10:21:04 +01:00
commit d4a67f0a30
2 changed files with 90 additions and 65 deletions

View File

@ -115,6 +115,27 @@ class BenutzerModel extends Database
}
public function nextId()
{
$pdo = $this->linkDB();
$sql = "SELECT `auto_increment` FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'Benutzerkonto'; ";
try {
$stmt = $pdo->prepare($sql);
$stmt->execute();
} catch (\PDOException $e) {
return false;
}
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
return $result;
}
}
?>

View File

@ -1,4 +1,4 @@
<?php
<?php
/*
Dieses Skript analysiert die URL und generiert daraus die passenden Controller-Aufrufe
@ -14,72 +14,76 @@
file_get_contents('php://input') die übergebenen json-Strings (für PUT/POST-Requests)
*/
spl_autoload_register(function ($className) {
if (substr($className, 0, 4) !== 'ppb\\') { return; }
$fileName = __DIR__.'/'.str_replace('\\', DIRECTORY_SEPARATOR, substr($className, 4)).'.php';
if (file_exists($fileName)) { include $fileName; }
});
$endpoint = explode('/', trim($_SERVER['PATH_INFO'],'/'));
$data = json_decode(file_get_contents('php://input'), true);
$controllerName = $endpoint[0];
$endpoint2 = isset($endpoint[1]) ? $endpoint[1] : false;
$id = false;
$alias = false;
if ($endpoint2) {
if (preg_match('/^[0-9]+$/', $endpoint2)) {
$id = $endpoint2;
} else {
$alias = $endpoint2;
}
spl_autoload_register(function ($className) {
if (substr($className, 0, 4) !== 'ppb\\') {
return;
}
$controllerClassName = 'ppb\\Controller\\'.ucfirst($controllerName). 'Controller';
if ($_SERVER['REQUEST_METHOD'] == "DELETE") {
$methodName = "delete" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "PUT") {
$methodName = "update" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
$methodName = "write" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "GET") {
if ($alias) {
$methodName = $alias;
} else {
$methodName = "get" . ucfirst($controllerName);
}
$fileName = __DIR__ . '/' . str_replace('\\', DIRECTORY_SEPARATOR, substr($className, 4)) . '.php';
if (file_exists($fileName)) {
include $fileName;
}
if (method_exists($controllerClassName, $methodName)) {
header('Content-Type: application/json');
$controller = new $controllerClassName();
//GET
if ($_SERVER['REQUEST_METHOD'] == "GET") {
echo $controller->$methodName($id);
} else
//POST
if ($_SERVER['REQUEST_METHOD'] == "POST"){
echo $controller->$methodName($data);
} else
//DELETE
if ($_SERVER['REQUEST_METHOD'] == "DELETE"){
echo $controller->$methodName($id);
} else
//PUT
{
echo $controller->$methodName($id, $data);
}
});
$endpoint = explode('/', trim($_SERVER['PATH_INFO'], '/'));
$data = json_decode(file_get_contents('php://input'), true);
$controllerName = $endpoint[0];
$endpoint2 = isset($endpoint[1]) ? $endpoint[1] : false;
$id = false;
$alias = false;
if ($endpoint2) {
if (preg_match('/^[0-9]+$/', $endpoint2)) {
$id = $endpoint2;
} else {
//http_response_code(404);
new \ppb\Library\Msg(true, 'Page not found: '.$controllerClassName.'::'.$methodName);
$alias = $endpoint2;
}
}
$controllerClassName = 'ppb\\Controller\\' . ucfirst($controllerName) . 'Controller';
if ($_SERVER['REQUEST_METHOD'] == "DELETE") {
$methodName = "delete" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "PUT") {
$methodName = "update" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
$methodName = "write" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "GET") {
if ($alias) {
$methodName = $alias;
} else {
$methodName = "get" . ucfirst($controllerName);
}
}
if (method_exists($controllerClassName, $methodName)) {
header('Content-Type: application/json');
$controller = new $controllerClassName();
//GET
if ($_SERVER['REQUEST_METHOD'] == "GET") {
echo $controller->$methodName($id);
} else
//POST
if ($_SERVER['REQUEST_METHOD'] == "POST") {
echo $controller->$methodName($data);
} else
//DELETE
if ($_SERVER['REQUEST_METHOD'] == "DELETE") {
echo $controller->$methodName($id);
} else
//PUT
{
echo $controller->$methodName($id, $data);
}
} else {
//http_response_code(404);
new \ppb\Library\Msg(true, 'Page not found: ' . $controllerClassName . '::' . $methodName);
}
?>