根据:
Silex - Service Controller Doc
我可以定义这样的路线(经过一些额外的corse代码之后):
$ app-> get('/ posts.json',“posts.controller:indexJsonAction”);
但是......我如何传递用于indexJsonAction函数的url?
答案 0 :(得分:2)
您应该将其直接映射到路线,例如:
$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
}