diff --git a/startmvc/Boot.php b/startmvc/Boot.php
index ea1c729f4ab11ce27a929dbad1a681245778458f..9c76103b8ba5de4173ea2e7c958d7cd306b6fea6 100644
--- a/startmvc/Boot.php
+++ b/startmvc/Boot.php
@@ -94,12 +94,15 @@ class Boot
}
private function startApp($module, $controller, $action, $argv) {
$controller = APP_NAMESPACE.'\\' . ($module != '' ? $module . '\\' : '') . 'Controller\\' . $controller . 'Controller';
- if (!class_exists($controller)) {
- header("HTTP/1.1 404 Not Found");
- header("Status: 404 Not Found");
+ $action .= 'Action';
+ if (!class_exists($controller) || !method_exists($controller, $action)) {
+ if ($this->conf['debug']) {
+ echo '控制器 ' . $controller . ' 或 方法 ' . $action . '不存在';
+ } else {
+ showErroPage(404);
+ }
die();
}
- $action .= 'Action';
Lib\Loader::make($controller, $action, $argv);
}
diff --git a/startmvc/Function.php b/startmvc/Function.php
index 959a450529e1ea206a7d0bef9685d2f5259c3b69..48ff630bb8e7b2a75856f8fe8a6be02756a37662 100644
--- a/startmvc/Function.php
+++ b/startmvc/Function.php
@@ -32,3 +32,71 @@
}
return $key?$lang[$key]:$key;
}
+ /**
+ * erro页面的处理
+ * @param int 错误代码
+ */
+ function showErroPage($errorCode=404)
+ {
+ sendHttpStatus($errorCode);
+ die('
404 Not Found');
+ }
+ /**
+ * 发送状态码
+ * @param int 状态码
+ */
+ function sendHttpStatus($i_status)
+ {
+ $a_status = array(
+ // Informational 1xx
+ 100 => 'Continue',
+ 101 => 'Switching Protocols',
+ // Success 2xx
+ 200 => 'OK',
+ 201 => 'Created',
+ 202 => 'Accepted',
+ 203 => 'Non-Authoritative Information',
+ 204 => 'No Content',
+ 205 => 'Reset Content',
+ 206 => 'Partial Content',
+ // Redirection 3xx
+ 300 => 'Multiple Choices',
+ 301 => 'Moved Permanently',
+ 302 => 'Found', // 1.1
+ 303 => 'See Other',
+ 304 => 'Not Modified',
+ 305 => 'Use Proxy', // 306 is deprecated but reserved
+ 307 => 'Temporary Redirect',
+ // Client Error 4xx
+ 400 => 'Bad Request',
+ 401 => 'Unauthorized',
+ 402 => 'Payment Required',
+ 403 => 'Forbidden',
+ 404 => 'Not Found',
+ 405 => 'Method Not Allowed',
+ 406 => 'Not Acceptable',
+ 407 => 'Proxy Authentication Required',
+ 408 => 'Request Timeout',
+ 409 => 'Conflict',
+ 410 => 'Gone',
+ 411 => 'Length Required',
+ 412 => 'Precondition Failed',
+ 413 => 'Request Entity Too Large',
+ 414 => 'Request-URI Too Long',
+ 415 => 'Unsupported Media Type',
+ 416 => 'Requested Range Not Satisfiable',
+ 417 => 'Expectation Failed',
+ // Server Error 5xx
+ 500 => 'Internal Server Error',
+ 501 => 'Not Implemented',
+ 502 => 'Bad Gateway',
+ 503 => 'Service Unavailable',
+ 504 => 'Gateway Timeout',
+ 505 => 'HTTP Version Not Supported',
+ 509 => 'Bandwidth Limit Exceeded'
+ );
+
+ if (array_key_exists($i_status, $a_status)) {
+ header('HTTP/1.1 ' . $i_status . ' ' . $a_status[$i_status]);
+ }
+ }