我有一些定义如下的路线:
$app->get('/user/posts', [
"as" => 'user.posts',
"uses" => 'UserController@getPosts'
]);
$app->get('/user/ads', [
"as" => 'user.ads',
"uses" => 'UserController@getAds'
]);
可以在我的第三条路线(如下)中通过它们的名称来调用这两条路线吗?类似反向路由的东西?
$app->get('/user/all', function() use ($app){
/** This does not work
$request = Request::create('MyRouteName', 'GET');
// I can't use the Route class in Lumen
$response = Route::dispatch($request);
**/
return [
"posts" => Request::response_from('user.posts'),
"ads" => Request::response_from('user.ads')
];
});
我想要一种Request::response_from($routeNameOrUri)
可以从路由中获取数据的方法(通过调用控制器的操作)