ThinkPHP开发技巧集锦(7):正则表达式定义路由规则
分析:
正常情况:两种路由均可以正常访问
Route::get('/product/recent','Product/getRecent');
Route::get('/product/:id','Product/getOne');
不正常情况:调换次序后,路由访问时会把 recent作为 id处理
Route::get('/product/:id','Product/getOne');
Route::get('/product/recent','Product/getRecent');
解决方案:
定义路由规则:id需为正整数,否则将跳过此路由继续向下执行['id'=>'\d+']
Route::get('/product/:id','Product/getOne',[],['id'=>'\d+']);
Route::get('/product/recent','Product/getRecent');
版权声明
本文仅代表作者观点,不代表博信信息网立场。