mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
Route类增加rest支持功能
例如:
Route::any('blog/:id','Blog/[rest]');
会自动根据当前的rest请求类型 定位到Blog控制器不同的get put delete put等操作方法
增加文件调度功能
例如:
Route::get('blog/:id',MODULE_PATH.'file/blog.php',['file'=>true]);
把blog/2 的URL请求调度到 MODULE_PATH.'file/blog.php' 文件执行后中止
This commit is contained in:
@@ -177,13 +177,17 @@ class Route {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(0 === strpos($rule, '/') && preg_match($rule, $regx, $matches)) { // 正则路由
|
if(0 === strpos($rule, '/') && preg_match($rule, $regx, $matches)) { // 正则路由
|
||||||
|
if(!empty($option['file'])){
|
||||||
|
// 调度到某个文件中执行
|
||||||
|
include $route;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
if($route instanceof \Closure) {
|
if($route instanceof \Closure) {
|
||||||
// 执行闭包并中止
|
// 执行闭包并中止
|
||||||
self::invokeRegx($route, $matches);
|
self::invokeRegx($route, $matches);
|
||||||
exit;
|
exit;
|
||||||
}else{
|
|
||||||
return self::parseRegex($matches, $route, $regx);
|
|
||||||
}
|
}
|
||||||
|
return self::parseRegex($matches, $route, $regx);
|
||||||
}else{ // 规则路由
|
}else{ // 规则路由
|
||||||
$len1 = substr_count($regx, '/');
|
$len1 = substr_count($regx, '/');
|
||||||
$len2 = substr_count($rule, '/');
|
$len2 = substr_count($rule, '/');
|
||||||
@@ -196,13 +200,17 @@ class Route {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(false !== $var = self::match($regx, $rule)){
|
if(false !== $var = self::match($regx, $rule)){
|
||||||
|
if(!empty($option['file'])){
|
||||||
|
// 调度到某个文件中执行
|
||||||
|
include $route;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
if($route instanceof \Closure) {
|
if($route instanceof \Closure) {
|
||||||
// 执行闭包并中止
|
// 执行闭包并中止
|
||||||
self::invokeRule($route, $var);
|
self::invokeRule($route, $var);
|
||||||
exit;
|
exit;
|
||||||
}else{
|
|
||||||
return self::parseRule($rule, $route, $regx);
|
|
||||||
}
|
}
|
||||||
|
return self::parseRule($rule, $route, $regx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -291,7 +299,8 @@ class Route {
|
|||||||
parse_str($url, $var);
|
parse_str($url, $var);
|
||||||
}
|
}
|
||||||
if(isset($path)) {
|
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)) {
|
if(!empty($path)) {
|
||||||
$_GET[Config::get('var_controller')] = array_pop($path);
|
$_GET[Config::get('var_controller')] = array_pop($path);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user