mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
_404方法并入E方法,用法:
原 _404('错误信息',$url);
改成 E('错误信息',404,$url);
$url参数如果省略则发送404头信息
This commit is contained in:
@@ -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']);
|
||||
|
||||
36
base.php
36
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名称
|
||||
|
||||
13
start.php
13
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();
|
||||
App::run();
|
||||
Reference in New Issue
Block a user