46 lines
No EOL
1.1 KiB
PHP
46 lines
No EOL
1.1 KiB
PHP
<?php
|
|
|
|
class Controller {
|
|
|
|
protected function model($model) {
|
|
$modelPath = __DIR__ . '/../app/models/' . $model . '.php';
|
|
if (file_exists($modelPath)) {
|
|
require_once $modelPath;
|
|
return new $model();
|
|
}
|
|
throw new Exception("Model '{$model}' existiert nicht.");
|
|
}
|
|
|
|
protected function view($view, $data = []) {
|
|
if (!empty($data)) {
|
|
extract($data);
|
|
}
|
|
|
|
$viewFile = __DIR__ . '/../views/' . $view . '.php';
|
|
|
|
if (file_exists($viewFile)) {
|
|
require_once $viewFile;
|
|
} else {
|
|
throw new Exception("View '{$view}' existiert nicht unter: {$viewFile}");
|
|
}
|
|
}
|
|
|
|
protected function json($data, $status = 200) {
|
|
http_response_code($status);
|
|
header('Content-Type: application/json');
|
|
echo json_encode($data);
|
|
exit;
|
|
}
|
|
|
|
protected function xml($data) {
|
|
header('Content-Type: application/xml; charset=utf-8');
|
|
echo $data;
|
|
exit;
|
|
}
|
|
|
|
protected function text($data) {
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo $data;
|
|
exit;
|
|
}
|
|
}
|