PHP Silex-服务控制器-传递参数

PHP Silex-服务控制器-传递参数,php,rest,service,controller,silex,Php,Rest,Service,Controller,Silex,根据: 我可以这样定义一条路线(在使用了两个额外的corse代码之后): $app->get('/posts.json',“posts.controller:indexJsonAction”) 但是。。。如何将使用的url传递给indexJsonAction函数?您应该将其直接映射到路由,例如: $app->get('/posts.json/{param1}/{param2}, 'posts.controller:indexJsonAction'); 这样,在控制器中,您可以预期以下参

根据:

我可以这样定义一条路线(在使用了两个额外的corse代码之后):

$app->get('/posts.json',“posts.controller:indexJsonAction”)


但是。。。如何将使用的url传递给indexJsonAction函数?

您应该将其直接映射到路由,例如:

$app->get('/posts.json/{param1}/{param2}, 'posts.controller:indexJsonAction');
这样,在控制器中,您可以预期以下参数:

public function indexJsonAction($param1, $param2) {
    //now you have access to these variables.
}
此外,silex在引擎盖下使用Symfony的请求,因此您也可以将请求注入控制器并从请求中获取任何输入

public function indexJsonAction(Request $request) {
    // use $request->get('param1'); etc
}

太好了,非常感谢。