pdo = $pdo; $this->view = $view; } /** * Render a template */ protected function render(Response $response, string $template, array $data = []): Response { // Add common admin data $data['auth'] = [ 'check' => isset($_SESSION['user_id']), 'user' => [ 'username' => $_SESSION['username'] ?? 'Admin', 'is_admin' => $_SESSION['is_admin'] ?? false ] ]; // Add current route for active menu highlighting $route = $this->getCurrentRoute(); if ($route) { $data['current_route'] = $route; } return $this->view->render($response, $template, $data); } /** * Get current route name */ protected function getCurrentRoute(): ?string { $route = $_SERVER['REQUEST_URI'] ?? '/'; $basePath = '/admin/'; if (strpos($route, $basePath) === 0) { $route = substr($route, strlen($basePath)); $parts = explode('/', $route); return $parts[0] ?: 'index'; } return null; } /** * Return JSON response */ protected function json(Response $response, $data, int $status = 200): Response { $response->getBody()->write(json_encode($data)); return $response ->withHeader('Content-Type', 'application/json') ->withStatus($status); } }