Why does the TP5 route fail to parse after adding dynamic parameters?

dynamically defines the route of a get request, which is OK without parameters, but not with dynamic parameters id

use think\Route;
Route::get("banner","api/v1.Banner/banner");

? >

the top is OK, but the bottom is not.

use think\Route;
Route::get("banner/:id","api/v1.Banner/banner");

? >

error message is:

clipboard.png

excuse me, what is this situation?

Php
Apr.18,2022

you can think of: id in banner/:id as a placeholder. All you have to do is replace it with the actual parameters.
eg:

  • banner/1

then define a parameter of $id in the parameters of the controller method to get it. Instead of getting it through $request.


above your URL is localhost/banner/?id=1
request directly with localhost/banner/1. When the controller receives parameters, it still uses id to receive

.
Menu