2

I have an API with some controllers for their respective entities. They have all the same structure, but in one of them I have this error when I try to delete a value.

No route found for "DELETE /api/categories/4": Method Not Allowed (Allow: GET, HEAD, PUT)

But I have the delete action created! And in other controllers, with the same code, it works fine.

The delete action:

/**     
 * @return array  
 * @Rest\Delete("/categories/{id}")      
 * @Rest\View(statusCode=204)
 * @Method({"DELETE"})       
 */
public function deleteCategoryAction($id)
{
    $em = $this->getDoctrine()->getManager(); 
    $category = $em->getRepository('CASEventBundle:Category')->find($id);

    $em->remove($category);
    $em->flush();

    return new View("deleted successfully", Response::HTTP_OK);
}

The routing file:

category:
    type: rest
    resource: CAS\APIRestBundle\Controller\CategoryController
yceruto
  • 9,230
  • 5
  • 38
  • 65
Brjtr
  • 157
  • 4
  • 17

2 Answers2

2

I have solved it. It was a class name that it was repeated in other file.

Brjtr
  • 157
  • 4
  • 17
0

I am not sure but try by using methods in route

category:
    type: rest
    resource: CAS\APIRestBundle\Controller\CategoryController
    methods: [DELETE]

Ref Here

Community
  • 1
  • 1
Gopal Joshi
  • 2,350
  • 22
  • 49
  • It doesn't works. It's very strange, because the other controllers work fine, and the others actions in CategoryController(get, post, put) also work well. – Brjtr Dec 28 '16 at 11:58