Files
pawra/src/Controller/BaseController.php
T
2026-04-21 13:56:05 +02:00

32 lines
726 B
PHP

<?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;
}
}