f3 = \Base::instance(); } // helper function protected function getDB() { return $this->f3->get('DB'); } /** * Enforce that the user is logged in before proceeding. */ protected function requireLogin() { // using trait $this->check_access($this->f3); return; // abstract if(!$this->f3->exists('SESSION.user')){ $this->f3->set('SESSION.redirect', $this->f3->get('PATH')); $this->f3->reroute('/login'); } } /** * Enforce that the user is logged in AND is an admin before proceeding. */ protected function requireAdmin() { $this->requireLogin(); // First, ensure the user is logged in // Check if the user is an admin (assuming 'is_admin' property in session) if (!$this->f3->get('SESSION.user.is_admin')) { // Optionally set an error message $this->f3->set('SESSION.error', 'Admin access required.'); $this->f3->reroute('/'); // Redirect non-admins to home page } } /** * Set up a main layout template and inject the specified view path * optional $data to pass variables down to template */ protected function renderView(string $viewPath, array $data = []):void { foreach($data as $key => $value){ $this->f3->set($key, $value); } // set {{content}} $this->f3->set('content', $viewPath); // render tempalte echo \Template::instance()->render('../ui/templates/layout.html'); // clear SESSION.error $this->f3->clear('SESSION.error'); } }