这条Symfony2路线出了什么问题?

Jer*_*cks 1 routing symfony

我已经使用注释建立了一条路线.看起来对我来说,Symfony2说这是错的.这是路线:

@Route("/news/{id}/{slug}", name="newsarticle")
Run Code Online (Sandbox Code Playgroud)

这是我认为与路线匹配的示例网址:

http://somesite.com/news/202/my-news-title

这是功能骨架:

public function newsArticleAction($id, $slug)
{

}
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?我收到500错误,日志说:

[2012-10-30 20:36:35] request.INFO:匹配路由"newsarticle"(参数:"_ control":"App\SiteBundle\Controller\DefaultController :: newsArticleAction","id":"202"," slug":"my-news-title","_ lute":"newsarticle")[] [] [2012-10-30 20:36:36] app.INFO:来自听众:"newsarticle"路线有些缺失强制参数("id").[] [] [2012-10-30 20:36:36] request.CRITICAL:Symfony\Component\Routing\Exception\MissingMandatoryParametersException:"newsarticle"路由有一些缺少必需参数("id").(未捕获的例外)/home/user/app/cache/prod/classes.php第676行[] []

Eln*_*mov 10

在将URL与路由匹配时,但在从路由生成URL时,不会出现此错误.

搜索您的项目path('newsarticle'generateUrl('newsarticle'.您应该尝试生成URL而不传递所有必需的参数 - 例如:

{{ path('newsarticle', {'slug': news.slug} }}
Run Code Online (Sandbox Code Playgroud)

虽然它必须看起来像:

{{ path('newsarticle', {'id': news.id, 'slug': news.slug} }}
Run Code Online (Sandbox Code Playgroud)