writeAlerts(); $response = $this->response; // For non-AJAX requests, we forward the user to the login page. if (!$this->request->isXhr()) { $uri = $this->request->getUri(); $path = $uri->getPath(); $query = $uri->getQuery(); $fragment = $uri->getFragment(); $path = $path . ($query ? '?' . $query : '') . ($fragment ? '#' . $fragment : ''); $loginPage = $this->ci->router->pathFor('login', [], [ 'redirect' => $path ]); $response = $response->withRedirect($loginPage); } return $response; } }