1
votes

I've set up a route using annotations. Looks right to me, Symfony2 says it's wrong. Here's the route:

@Route("/news/{id}/{slug}", name="newsarticle")

Here's a sample URL which I think matches the route:

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

Here is the function skeleton:

public function newsArticleAction($id, $slug)
{

}

What am I missing here? I get a 500 error and the log says:

[2012-10-30 20:36:35] request.INFO: Matched route "newsarticle" (parameters: "_controller": "App\SiteBundle\Controller\DefaultController::newsArticleAction", "id": "202", "slug": "my-news-title", "_route": "newsarticle") [] [] [2012-10-30 20:36:36] app.INFO: From listener: The "newsarticle" route has some missing mandatory parameters ("id"). [] [] [2012-10-30 20:36:36] request.CRITICAL: Symfony\Component\Routing\Exception\MissingMandatoryParametersException: The "newsarticle" route has some missing mandatory parameters ("id"). (uncaught exception) at /home/user/app/cache/prod/classes.php line 676 [] []

1
There doesn't appear to be anything wrong with the route. From the log it looks like it matched the route fine. Your template may be trying to generate the URL for newsarticle and doesn't have all the required params to generate it, to which it will throw this exact exception.noetix
Did you clear the cache? Try the app_dev.php which may print out more information on what's going wrong.Sgoettschkes

1 Answers

10
votes

This error comes up not when matching a URL to a route, but when generating a URL from a route.

Search your project for path('newsarticle' or generateUrl('newsarticle'. You should find an attempt to generate a URL without passing all the needed parameters — something like:

{{ path('newsarticle', {'slug': news.slug} }}

while it has to look like:

{{ path('newsarticle', {'id': news.id, 'slug': news.slug} }}