thinkphp路由

官方文档地址

https://www.kancloud.cn/manual/thinkphp5/118019

3种路由模式

path_info模式 混合模式 强制路由模式

在编写api时候,建议使用强制路由模式

'url_route_on'  		=>  true,
'url_route_must'		=>  true,

完整匹配

'hello/[:name]$' => 'index/hello',
当路由规则以 $ 结尾的时候就表示当前路由规则需要完整匹配。
当我们访问下面的URL地址的时候:
http://tp5.com/hello // 正确匹配
http://tp5.com/hello/thinkphp // 正确匹配
http://tp5.com/hello/thinkphp/val/value // 不会匹配

设置URL分隔符

application/config.php中
// 设置pathinfo分隔符
'pathinfo_depr' => '-',
路由规则定义无需做任何改变,我们就可以访问下面的地址:
http://tp5.com/hello-thinkphp

路由接口版本设置

<?php
usethinkRoute;

//Route::rule('路由表达式','路由地址','请求类型','路由参数(数组)','变量规则(数组)');
Route::get('api/:v/banner/:id','api/:v.Banner/getBanner');

//分组
Route::group('api/:v',function(){
Route::get('/theme','api/:v.theme/getSimpleList');
Route::get('/theme/:id','api/:v.theme/getComplexOne');
});
原文地址:https://www.cnblogs.com/qinsilandiao/p/13432385.html