thinkphp5 怎么设置全局路由
1、一种是在application/route.php中配置:示例:
return [
'__pattern__' => [
'name' => '\w+',
],
'[hello]' => [
':id' => ['index/hello', ['method' => 'get'], ['id' => '\d+']],
':name' => ['index/hello', ['method'=> 'post']],
],
];
2、一种是动态注册:示例:把route.php中官方配置的代码删掉,然后写如下代码:
use think\Route;
Route::rule(‘hello’,’sample/test/hello’);
3、注意:对某个方法进行动态注册路由之后,之前的pathinfo模式就失效了,只是对当前这个方法失效,其它方法还是可以正常使用pathinfo。
4、也可以在配置文件中设置强制使用路由模式,在application\config.php中找到。
5、‘url_route_must’设置为true,就全部只能用路由模式了。
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:177
阅读量:39
阅读量:101
阅读量:138
阅读量:111