owowowo
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
abstract class BaseController
|
||||
{
|
||||
protected function render(string $view, array $data = []): void
|
||||
{
|
||||
extract($data);
|
||||
|
||||
$viewPath = __DIR__ . '/../../views/' . $view . '.php';
|
||||
|
||||
if (!file_exists($viewPath)) {
|
||||
http_response_code(500);
|
||||
echo "View '{$view}' nicht gefunden.";
|
||||
return;
|
||||
}
|
||||
|
||||
require $viewPath;
|
||||
}
|
||||
|
||||
protected function redirect(string $url): void
|
||||
{
|
||||
header('Location: ' . $url);
|
||||
exit;
|
||||
}
|
||||
|
||||
protected function json(mixed $data, int $status = 200): void
|
||||
{
|
||||
http_response_code($status);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user