1

I was trying to create a route type "any" to allow both get and post but it did not work so I tried adding two routes to my route annotation like this

 /**
 * @Route("/news", name="newsSinglePOST", methods={"post"})
 * @Route("/news", name="newsSingleGET", methods={"get"})
 * @return \Symfony\Component\HttpFoundation\Response
 */

That did not work either but then I tried deleting one but the route is now unusable, the controller does says something about a missing return statement and in my router I have the following line:

newsGet ANY ANY ANY /news

to get my controller working again I had to change /news to news2 so this route is now somehow unusable

I tried clearing the dev cache without success

So my question is how can I recover my route /news ?

Imanali Mamadiev
  • 2,604
  • 2
  • 15
  • 23
Sam
  • 1,557
  • 3
  • 26
  • 51
  • You must uppercase the method names – Matías Navarro Carter Aug 27 '18 at 14:52
  • Don't use two Annotations entry. The correct way is `* @Route("/news", name="newsSingleGET", methods="GET|POST")` – Marcos Regis Aug 27 '18 at 15:19
  • @MarcosRegis your suggestion is in my opinion simpler and better than the one suggested below, post an answer and I'll accept – Sam Aug 27 '18 at 18:06
  • I made a test here and I was wrong. The way you did work on Symfony 4.1 using *Symfony\Component\Routing\Annotation\Route;* ` * @Route("/news", name="newsSinglePOST", methods={"post"})` ` * @Route("/news", name="newsSingleGET", methods={"get"})` When I ran `php bin/console debug:router` both routes are shown. Which version of Symfony? – Marcos Regis Aug 27 '18 at 19:54
  • Check [this](http://www.inanzzz.com/index.php/post/o6hp/organising-routes-within-symfony4-applications) and [this](http://www.inanzzz.com/index.php/post/7f0h/organising-routes-and-controllers-in-symfony-4-applications). – BentCoder Aug 28 '18 at 11:21

2 Answers2

0

Did you tried to use the method annotation like this ?

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

/**
 * @Route("/news", name="news")
 * @Method("GET|POST")
 * @return \Symfony\Component\HttpFoundation\Response
 */
Jérôme
  • 1,966
  • 4
  • 24
  • 48
0

You can use the following solution:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

/**
 * @Route("/news", name="newsSinglePOST")
 * @Route("/news", name="newsSingleGET")
 * @Method({"GET", "POST"})
 */
Grant Miller
  • 27,532
  • 16
  • 147
  • 165
Imanali Mamadiev
  • 2,604
  • 2
  • 15
  • 23