api版本号的传入方式有:请求头传入、请求参数传入、路由方式。
请求参数传入方式:
Route::rule(':version/user/:id','api/:version.User/read');
不同版本的URL访问地址为:http://tp5.com/v1/user/10
http://tp5.com/v2/user/10
版本号中不能包含.符号。
请求头传入方式:
在route.PHP路由文件中配置,如下
$version = request()->header('version');
if($version==null) $version = "v1";
return [
//api版本控制
'api/:controller'=>['api/'.$version.'.:controller/index',['method' => 'get']],
'api/:controller/:function'=>'api/'.$version.'.:controller/:function',
//资源路由
'__rest__'=>[
'api/book'=>['api/'.$version.'.book_rent',['only'=>['index','read','save']]],
]
]
详细请看这篇博文:http://blog.csdn.net/veloi/article/details/73848781 最佳答案
