diff --git a/Think/App.php b/Think/App.php index ba4ab13f..e60614c9 100644 --- a/Think/App.php +++ b/Think/App.php @@ -59,7 +59,7 @@ class App { // 是否定义empty控制器 $instance = Loader::controller('empty'); if(!$instance){ - _404('controller not exists :'.CONTROLLER_NAME); + E('controller not exists :'.CONTROLLER_NAME,404); } } @@ -96,7 +96,7 @@ class App { }elseif($param->isDefaultValueAvailable()){ $args[] = $param->getDefaultValue(); }else{ - _404('_PARAM_ERROR_:'.$name); + E('_PARAM_ERROR_:'.$name); } } $method->invokeArgs($instance,$args); @@ -115,7 +115,7 @@ class App { $method = new \ReflectionMethod($instance,'_empty'); $method->invokeArgs($instance,array($action,'')); }else{ - _404('action not exists :'.ACTION_NAME); + E('action not exists :'.ACTION_NAME,404); } } // 监听app_end @@ -247,7 +247,7 @@ class App { $var_c = $config['var_controller']; $var_a = $config['var_action']; }else{ - _404('module not exists :'.MODULE_NAME); + E('module not exists :'.MODULE_NAME,404); } // 路由检测和控制器、操作解析 Route::check($_SERVER['PATH_INFO']); diff --git a/base.php b/base.php index e815ab48..7a8ec541 100644 --- a/base.php +++ b/base.php @@ -126,7 +126,19 @@ function import($class, $baseUrl = '', $ext= EXT ) { * @param integer $code 异常代码 默认为0 * @return void */ -function E($msg, $code=0) { +function E($msg, $code=0,$url='') { + if(404 == $code && !C('app_debug')) { + if($msg) Think\Log::record($msg,'ERR'); + $url = $url?$url:C('url_404_redirect'); + if($url) { + header('Location: ' . $url); + }else{ + header('HTTP/1.1 404 Not Found'); + // 确保FastCGI模式下正常 + header('Status:404 Not Found'); + } + exit; + } throw new Think\Exception($msg, $code); } @@ -141,28 +153,6 @@ function dump($var, $echo=true, $label=null) { return Think\Debug::dump($var,$echo,$label); } -/** - * 404处理 - * 调试模式会抛异常 - * 部署模式下面传入url参数可以指定跳转页面,否则发送404信息 - * @param string $msg 提示信息 - * @param string $url 跳转URL地址 - * @return void - */ -function _404($msg='',$url='') { - Think\Config::get('app_debug') && E($msg); - if($msg) Think\Log::record($msg,'ERR'); - $url = $url?$url:Think\Config::get('url_404_redirect'); - if($url) { - header('Location: ' . $url); - }else{ - header('HTTP/1.1 404 Not Found'); - // 确保FastCGI模式下正常 - header('Status:404 Not Found'); - } - exit; -} - /** * 渲染输出Widget * @param string $name Widget名称 diff --git a/start.php b/start.php index b6a257b8..14ef6f53 100644 --- a/start.php +++ b/start.php @@ -40,15 +40,13 @@ Config::load(THINK_PATH.'convention.php'); Log::init(['type'=>Config::get('log_type'),'log_path'=> Config::get('log_path')]); // 缓存初始化 -Cache::connect(['type'=>Config::get('cache_type'),'temp'=> CACHE_PATH]); +//Cache::connect(['type'=>Config::get('cache_type'),'temp'=> CACHE_PATH]); // 注册行为扩展 -//ThinkTag::add('route_check','route_check'); -Tag::add('content_filter','ContentReplace','Think'); +//Tag::add('content_filter','ContentReplace','Think'); //Tag::add('app_end','ShowPageTrace','Think'); Tag::add('view_template','LocationTemplate','Think'); -//Tag::add('action_begin','BeforeAction','Index'); -//Tag::add('app_end','test','Index'); + // 启动session if(!IS_CLI) { @@ -56,7 +54,4 @@ if(!IS_CLI) { } // 执行应用 -App::run(); - -// 保存日志 -//Log::save(); \ No newline at end of file +App::run(); \ No newline at end of file