From bb8ce3fcf07f3dcf8f6e3658aec6da28ef126bf5 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 1 Apr 2013 18:18:19 +0800 Subject: [PATCH] =?UTF-8?q?=5F404=E6=96=B9=E6=B3=95=E5=B9=B6=E5=85=A5E?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E7=94=A8=E6=B3=95=EF=BC=9A=20?= =?UTF-8?q?=E5=8E=9F=20=5F404('=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF',$url)?= =?UTF-8?q?;=20=E6=94=B9=E6=88=90=20E('=E9=94=99=E8=AF=AF=E4=BF=A1?= =?UTF-8?q?=E6=81=AF',404,$url);=20$url=E5=8F=82=E6=95=B0=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E7=9C=81=E7=95=A5=E5=88=99=E5=8F=91=E9=80=81404?= =?UTF-8?q?=E5=A4=B4=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Think/App.php | 8 ++++---- base.php | 36 +++++++++++++----------------------- start.php | 13 ++++--------- 3 files changed, 21 insertions(+), 36 deletions(-) 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