From 2244002a95333147bfcfcecc81e4104f883ffa01 Mon Sep 17 00:00:00 2001 From: ThinkPHP Date: Thu, 4 Jul 2013 15:19:00 +0800 Subject: [PATCH] =?UTF-8?q?Route=E7=B1=BB=E5=A2=9E=E5=8A=A0rest=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8A=9F=E8=83=BD=20=E4=BE=8B=E5=A6=82=EF=BC=9A=20Rou?= =?UTF-8?q?te::any('blog/:id','Blog/[rest]');=20=E4=BC=9A=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=A0=B9=E6=8D=AE=E5=BD=93=E5=89=8D=E7=9A=84rest?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=B1=BB=E5=9E=8B=20=E5=AE=9A=E4=BD=8D?= =?UTF-8?q?=E5=88=B0Blog=E6=8E=A7=E5=88=B6=E5=99=A8=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=9A=84get=20put=20delete=20put=E7=AD=89=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加文件调度功能 例如: Route::get('blog/:id',MODULE_PATH.'file/blog.php',['file'=>true]); 把blog/2 的URL请求调度到 MODULE_PATH.'file/blog.php' 文件执行后中止 --- Library/Think/Route.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Library/Think/Route.php b/Library/Think/Route.php index 2311d607..9f7ee14f 100644 --- a/Library/Think/Route.php +++ b/Library/Think/Route.php @@ -177,13 +177,17 @@ class Route { } } if(0 === strpos($rule, '/') && preg_match($rule, $regx, $matches)) { // 正则路由 + if(!empty($option['file'])){ + // 调度到某个文件中执行 + include $route; + exit; + } if($route instanceof \Closure) { // 执行闭包并中止 self::invokeRegx($route, $matches); exit; - }else{ - return self::parseRegex($matches, $route, $regx); } + return self::parseRegex($matches, $route, $regx); }else{ // 规则路由 $len1 = substr_count($regx, '/'); $len2 = substr_count($rule, '/'); @@ -196,13 +200,17 @@ class Route { } } if(false !== $var = self::match($regx, $rule)){ + if(!empty($option['file'])){ + // 调度到某个文件中执行 + include $route; + exit; + } if($route instanceof \Closure) { // 执行闭包并中止 self::invokeRule($route, $var); exit; - }else{ - return self::parseRule($rule, $route, $regx); } + return self::parseRule($rule, $route, $regx); } } } @@ -291,7 +299,8 @@ class Route { parse_str($url, $var); } if(isset($path)) { - $_GET[Config::get('var_action')] = array_pop($path); + $action = array_pop($path); + $_GET[Config::get('var_action')] = '[rest]'==$action? REQUEST_METHOD : $action; if(!empty($path)) { $_GET[Config::get('var_controller')] = array_pop($path); }