Thinkphp route matching problem

Route::post("xdk/plan","xdk/plan/save");
Route::post("xdk/plan/:id/fav","xdk/plan/fav");
Route::post("xdk/plan/:id/comments","xdk/plan/comments"); //

is to build a restful style api
/ xdk/plan post
/ xdk/plan/:id/fav like
/ xdk/plan/:id/comments comment

Why did

/ xdl/plan/2/fav match into the first release route?

Mar.12,2021

there is an exact match in the configuration file

 // 
    'route_complete_match'   => true,

Route::post('xdk/plan$','xdk/plan/save');
Route::post('xdk/plan/:id/fav$','xdk/plan/fav');
Route::post('xdk/plan/:id/comments$','xdk/plan/comments'); //

first of all, you can add a $ at the end of each route to avoid this situation.
secondly, tp5 has its own routing function that supports RESTFul, which only needs

.
Route::resource('xdk/plan','xdk/plan');

can achieve resource routing. For more information, please see the official document: tp resource routing

. The route of

Thinkphp5 is matched one by one from top to bottom, and the fourth parameter of the route can be used to match the regular expression.

Menu