关于tp5.0.2的路由规则一些问题请教

浏览:413 发布日期:2016/11/07 分类:ThinkPHP5专区
简单的需求就是用一个命名,根据请求类型来决定最后路由的方法,看了文档的例子如:Route::rule([
['blog/:id','Blog/read',['method'=>'get']],
['blog/:id','Blog/update',['method'=>'post']],
...
],'','*',['ext'=>'html'],['id'=>'\d+']);
但是实际测试老是报错:
一种是在route.php中增加如下代码:use think\Route;
Route::rule([
    ['hi/[:id]','test/Index/test',['method'=>'get']],
    ['hi/[:id]','test/Index/testpost',['method'=>'post']],
],'','*',['ext'=>'html'],['id'=>'\d+']);
会报hi模块不存在的错误

还有直接在return里面加:'hi' => [
        ['test/index/test', ['method' => 'get']],
        ['test/index/testpost', ['method' => 'post']],
    ],
依然报错
[2] ErrorException in Route.php line 1402 return ['type' => 'response', 'response' => $result];
                } elseif (is_array($result)) {
                    return $result;
                }
            }

            if ($route instanceof \Closure) {
                // 执行闭包
                $result = ['type' => 'function', 'function' => $route];
            } elseif (0 === strpos($route, '/') || 0 === strpos($route, 'http')) {        <-----------------这里
                // 路由到重定向地址
                $result = ['type' => 'redirect', 'url' => $route, 'status' => isset($option['status']) ? $option['status'] : 301];
            } elseif (false !== strpos($route, '\\')) {
                // 路由到方法
                $route  = str_replace('/', '@', $route);
                $method = strpos($route, '@') ? explode('@', $route) : $route;
                $result = ['type' => 'method', 'method' => $method];
            } elseif (0 === strpos($route, '@')) {
                // 路由到控制器
求指教应该怎么配置




最佳答案
评论( 相关
后面还有条评论,点击查看>>