new init
This commit is contained in:
1 parent
3bd3214e48
commit
deacdadb5c
2 files changed
+42
-6
No files matched your search
@@ -5,7 +5,7 @@
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"workbench.colorTheme": "Dark Modern",
|
||||
"workbench.colorTheme": "Monokai",
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.background": "#162df7ec",
|
||||
"activityBar.foreground": "#000000",
|
||||
|
||||
@@ -65,7 +65,7 @@ $host = 'localhost';
|
||||
$root = __DIR__ . '/WEBROOT';
|
||||
echo "\n🚀 Starte MVC Dev-Server auf http://$host:$port\n";
|
||||
echo "Drücke STRG+C zum Beenden.\n\n";
|
||||
passthru("php -S $host:$port -t \"$root\"");
|
||||
passthru("php -S $host:$port -t \"$root\" \"$root/index.php\"");
|
||||
PHP;
|
||||
|
||||
$files['WEBROOT/logs/error.log'] = <<<'LOG'
|
||||
@@ -1173,14 +1173,24 @@ class Router {
|
||||
protected $routes = [];
|
||||
protected $middlewares = [];
|
||||
|
||||
public function add($service, $controller, $method, $middlewares = []) {
|
||||
public function add($service, $controller, $method, $middlewares = [], $isApi = null) {
|
||||
// Auto-detect API route if $isApi is not explicitly set
|
||||
if ($isApi === null) {
|
||||
$isApi = strpos($service, 'api/') === 0;
|
||||
}
|
||||
|
||||
$this->routes[$service] = [
|
||||
'controller' => $controller,
|
||||
'method' => $method,
|
||||
'middlewares' => $middlewares
|
||||
'middlewares' => $middlewares,
|
||||
'isApi' => $isApi
|
||||
];
|
||||
}
|
||||
|
||||
public function getRoute($service) {
|
||||
return $this->routes[$service] ?? null;
|
||||
}
|
||||
|
||||
public function dispatch($service) {
|
||||
if (!isset($this->routes[$service])) {
|
||||
throw new \Exception("Service '$service' not found.");
|
||||
@@ -2242,6 +2252,9 @@ $router->add('template_download', \MVC\Controller\TemplateController::class, 'do
|
||||
$router->add('template_form', \MVC\Controller\TemplateController::class, 'data_form', ['auth']);
|
||||
$router->add('template_table', \MVC\Controller\TemplateController::class, 'data_table', ['auth']);
|
||||
$router->add('download_file', \MVC\Controller\TemplateController::class, 'download_file', ['auth']);
|
||||
|
||||
// API Routes (Path-based)
|
||||
$router->add('api/v1/test', \MVC\Controller\ApiController::class, 'get');
|
||||
PHP;
|
||||
|
||||
// --- CONFIG: navigation.php ---
|
||||
@@ -2273,13 +2286,36 @@ require_once __DIR__ . '/src/MVC/autoloader.php';
|
||||
use MVC\Classes\Logger;
|
||||
set_exception_handler([Logger::class, 'logException']);
|
||||
set_error_handler([Logger::class, 'logError']);
|
||||
$service = $_GET['service'] ?? 'home';
|
||||
|
||||
// 1. Determine the service
|
||||
$service = $_GET['service'] ?? null;
|
||||
|
||||
// Fallback to path-based routing if no service parameter is given
|
||||
if ($service === null) {
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
$service = trim($uri, '/');
|
||||
if (empty($service)) {
|
||||
$service = 'home';
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$router = new \MVC\Core\Router();
|
||||
|
||||
// Load routes from config
|
||||
require_once __DIR__ . '/src/config/routes.php';
|
||||
|
||||
// 2. Dispatch the service
|
||||
$routeInfo = $router->getRoute($service);
|
||||
$output = $router->dispatch($service);
|
||||
|
||||
// 3. Conditional Layout Rendering
|
||||
if ($routeInfo && !empty($routeInfo['isApi'])) {
|
||||
// API Route: Just echo the output and exit
|
||||
echo $output;
|
||||
exit;
|
||||
}
|
||||
|
||||
$layout = new \MVC\Layout\Layout('main');
|
||||
$layout->setBlock('title', 'MVC Starter');
|
||||
$layout->setBlock('header_title', '🚀 MVC Dashboard');
|
||||
@@ -2321,7 +2357,7 @@ try {
|
||||
<?php
|
||||
$layout->setBlock('sidebar', ob_get_clean());
|
||||
|
||||
$layout->setBlock('content', $router->dispatch($service));
|
||||
$layout->setBlock('content', $output);
|
||||
echo $layout->render();
|
||||
} catch (\Throwable $e) {
|
||||
Logger::logException($e);
|
||||
|
||||
Reference in new issue
Block a user