3

My routing definition looks like this (using this as reference to have better order in the code):

$app->get('/actor/{id}', 'TMDb\Controller\TMDbController::actorAction');

And this is how my controller looks like:

class TMDbController {
    public function actorAction(Request $request, Application $app) { ... }
} 

And it worked, but I haven't found the way to get in my action controller the id value.

4

1 回答 1

4

就这么简单:

public function actorAction($id, Request $request, Application $app)

Silex(实际上是 Symfony2 的 HttpFoundation)将命名参数从 url 传递给具有相同名称的函数参数。

您还应该检查参数转换器,以便您的控制器获取 id 引用的对象(或数组),而不是普通的 id。

于 2013-07-26T14:55:56.120 回答