function test_header_status_string_works_with_many_status() { $this->assertEquals("HTTP/1.1 200 OK", No2_HTTP::header_status_string(200)); $this->assertEquals("HTTP/1.1 303 See Other", No2_HTTP::header_status_string(303)); $this->assertEquals("HTTP/1.1 403 Forbidden", No2_HTTP::header_status_string(403)); $this->assertEquals("HTTP/1.1 404 Not Found", No2_HTTP::header_status_string(404)); $this->assertEquals("HTTP/1.1 500 Internal Server Error", No2_HTTP::header_status_string(500)); }
<?php /* * some expected error status code have a more userfriendly message than the raw HTTP reason * phrase. */ $status = $this->status(); switch ($status) { case No2_HTTP::NOT_FOUND: $message = t('404 Page not found.'); break; case No2_HTTP::UNAUTHORIZED: $message = t('You are not authorized to access this page.'); break; default: $http_status_string = No2_HTTP::header_status_string($status); if (!is_null($http_status_string)) { $message = preg_replace('/HTTP\\/\\d+\\.\\d+\\s*/', '', $http_status_string); } else { $message = "An error occured."; } } ?> <h1><?php print t('Oups!'); ?> </h1> <p><?php print h($message); ?>
/** * A very simple error page. * * This method is intended to be overrided by subclass to handle errors in * a more friendly way. */ protected function render_error() { $http_status_string = No2_HTTP::header_status_string($this->status()); if (!is_null($http_status_string)) { $message = preg_replace('/HTTP\\/\\d+\\.\\d+\\s*/', '', $http_status_string); } else { $message = "An error occured."; } ?> <html> <head><title><?php print h($message); ?> </title></head> <body> <h1>Error: <?php print h($message); ?> </h1> </body> </html> <?php }