/** * @fn error($code, $headers) * @short Redirects the request to the error page for the desired HTTP error code. * @details This method redirects the request to the ErrorController action method that * handles the HTTP error code <tt>code</tt>, optionally sending a set of headers. * @param code The HTTP error code. * @param headers An optional set of HTTP headers to send to the client. */ public static function error($code = 500, $headers = array()) { if ($code != 400) { $error = new ServerError(array('code' => $code, 'description' => var_export($_SERVER, TRUE), 'occurred_at' => date('Y-m-d H:i:s'))); $error->save(); } foreach ($headers as $header => $value) { header("{$header}: {$value}"); } $_SESSION['error_processed'] = TRUE; header(sprintf("Location: http://%s%serror/%s.html", $_SERVER['HTTP_HOST'], APPLICATION_ROOT, $code)); exit; }
/** * @fn generate_error($code) * @short Private common error handler. * @param code An error code. */ private function generate_error($code) { $desc = self::$descriptions[$code]; header("HTTP/1.1 {$code} {$desc}"); if (isset($_SESSION['error_processed'])) { unset($_SESSION['error_processed']); return; } if ($code == 404) { return; } $error = new ServerError(array('code' => $code, 'description' => var_export($_SERVER, TRUE), 'occurred_at' => date('Y-m-d H:i:s'))); $error->save(); }