How to declare both method in routing.yml Symfony2?

Antoine Subit picture Antoine Subit · Apr 9, 2014 · Viewed 7.7k times · Source

I want to declare both methods GET and POST for a same route in my routing.yml.

According the documentation it's possible with annotations like that :

/**
 * @Route("/edit/{id}")
 * @Method({"GET", "POST"})
 */

But how to YAML ? I tried different things :

contact_envoi:
    pattern:  /contact-envoi
    defaults: { _controller: AcmeDemoBundle:Default:contactEnvoi }
    requirements:
        sf_method: ['get','post']

and

...
    requirements:
        _method: { 'GET', 'POST' }

but it still doesn't work ... Please help, I found nothing in the documentation about that.

Answer

Antoine Subit picture Antoine Subit · Apr 9, 2014

Thanks to Touki for his comment, it works!

I had to declare twice the same URL on two separate shares and each with their own method as explained here for Symfony 2.1 and here for Symfony 2.2.

contact:
    path:     /contact
    defaults: { _controller: AcmeDemoBundle:Main:contact }
    methods:  [GET]

contact_process:
    path:     /contact
    defaults: { _controller: AcmeDemoBundle:Main:contactProcess }
    methods:  [POST]