Form works with GET but not with POST in the controller

2

I am working with Symfony 4 and I am trying to send a form by the POST method to a function inside a Controller, but I get an error saying that the Controller does not exist. If I send it by the GET method, everything goes well, that is, the path is correct.

The Route I define it in the same function of the Controller like this:

/**
 * @Route("/mi_controller/my_function/", name="mi_route")
 */
public function mi_funciton(){....

Later in the view I create the form like this:

<form action="{{ path('mi_route') }}" method="post" >

If I change the method to GET, it addresses me well, but with POST it says Controller indefinite. Why does that happen and how can I solve it?

    
asked by German Kinen 25.12.2017 в 18:59
source

2 answers

2

According to the Documentation you can specify the annotation @Method a its driver to specify the method HTTP

/**
 * @Route("/mi_controller/my_function/", name="mi_route")
 * @Method({"POST"})
 */
public function mi_funciton(){....
    
answered by 26.12.2017 в 03:18
0

It should work without any problem indicating in the form that the data should go through POST.

It would be interesting if you showed us how you intend to collect that data that comes through POST in the controller. I always do it this way

public function mi_funciton(Request $request){
    $request->get('name-del-imput');
}

or directly I use the symfony form components. There you have all the documentation: link

    
answered by 06.03.2018 в 12:28