use Webman\Route;
Route::group('/blog', function () {
Route::any('/create', [app\controller\UserController::class, 'hello'])->name('11222');
});
public function hello(Request $request)
{
$route = $request->route;
var_export($route->getPath());
var_export('ok');
// return response('name ' . $route->getName());
}
Error: Call to undefined method Webman\Route\Route::getPath()
http://www.wtbis.cn/doc/webman/request.html#%E8%8E%B7%E5%8F%96%E8%AF%B7%E6%B1%82%E8%B7%AF%E5%BE%84
http://www.wtbis.cn/doc/webman/route.html#%E8%8E%B7%E5%8F%96%E8%B7%AF%E7%94%B1%E4%BF%A1%E6%81%AF
麻煩看下文檔
$request->path();是可以獲取到
$route = $request->route;
$route->getMethods(); 這個(gè)是報(bào)錯(cuò)
$route->getName();這個(gè)是正常
$route->getMethods(); 得到的是這東西 ["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS"] ,而且你要走路由管理的路由,不然$route是null
走路由管理配置的沒(méi)有任何問(wèn)題,你說(shuō)$route不是null,打印截圖貼出來(lái)。
Error: Call to undefined method Webman\Route\Route::getPath() 報(bào)錯(cuò)這這里呢,你別騙我,我讀書(shū)少
OK的
Route::any('/api', [\app\controller\ApiController::class, 'index'])->name('11222');
public function index(Request $request): Response
{
$route = $request->route;
var_export($route);
var_export($route->getPath());
return json($route->getPath());
}
我是剛學(xué)習(xí),就按照文檔做的,就這一段代碼
$route = $request->route;
var_dump($route->getPath());
我在win上面又試了試,沒(méi)有問(wèn)題
在docker出現(xiàn)了問(wèn)題
https://github.com/walkor/webman-framework/blob/v1.4.9/src/Route/Route.php#L106
那就是你不小心改動(dòng)了webman-framework 源碼了
看了一下webman-framework源碼,getPath沒(méi)問(wèn)題,應(yīng)該是你改動(dòng)了源碼,重新install試試