From a20a307e0aa0ae856e719f49a35a92b052f96e36 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 15 Apr 2016 15:16:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BRoute=E7=B1=BB=20=E5=AF=B9?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=96=B9=E6=B3=95=E5=89=8D=E7=BC=80=E7=9A=84?= =?UTF-8?q?=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 86283ed5..f53ec508 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -37,10 +37,10 @@ class Route // 不同请求类型的方法前缀 private static $methodPrefix = [ - 'GET' => '', - 'POST' => '', - 'PUT' => '', - 'DELETE' => '', + 'GET' => 'get', + 'POST' => 'post', + 'PUT' => 'put', + 'DELETE' => 'delete', ]; // URL映射规则 @@ -227,7 +227,9 @@ class Route // 注册别名路由 public static function alias($rule, $route = '', $option = [], $pattern = []) { - self::any($rule . '/:action', $route . '/:action', $option, $pattern); + foreach (self::$methodPrefix as $type => $val) { + self::$type($rule . '/:action', $route . '/' . $val . ':action', $option, $pattern); + } } // 设置不同请求类型下面的方法前缀 @@ -608,8 +610,9 @@ class Route // REST 操作方法支持 if ('[rest]' == $action) { $action = REQUEST_METHOD; - } elseif (isset(self::$methodPrefix[REQUEST_METHOD])) { - $action = self::$methodPrefix[REQUEST_METHOD] . $action; + } elseif (Config::get('use_action_prefix') && !empty(self::$methodPrefix[REQUEST_METHOD])) { + // 操作方法前缀支持 + $action = 0 !== strpos($action, self::$methodPrefix[REQUEST_METHOD]) ? self::$methodPrefix[REQUEST_METHOD] . $action : $action; } } $route = [$module, $controller, $action];