Search code examples
symfonydoctrine-ormfosrestbundle

Method Not Allowed with FosRestBundle


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

Solution

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