Jhonne
Jhonne

Reputation: 424

Add requirements for route with annotations

I am using the SensioFrameworkExtraBundle and trying to add a requirement for a specific parameter. I want the parameter to match a specific collection of strings.

This example from the Symfony documentation shows what I want to do. I want to do the same thing as done with culture and _format.

article_show:
    path:     /articles/{culture}/{year}/{title}.{_format}
    defaults: { _controller: AcmeDemoBundle:Article:show, _format: html }
    requirements:
        culture:  en|fr
        _format:  html|rss
        year:     \d+

This is my code:

 /**
  * @Route("/{type}", requirements={"type" = {html|json|xml} }, name="adm_grid")
  * @Template
 */

Upvotes: 3

Views: 3518

Answers (1)

Elnur Abdurrakhimov
Elnur Abdurrakhimov

Reputation: 44841

You forgot the quotes around {html|json|xml} and you don't need the curly braces:

 requirements={"type" = "html|json|xml"}

Upvotes: 7

Related Questions