Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
DELETE method in REST controller - How to handle?
  • Hi, I have a problem handling DELETE method in REST controller using following element URI:
    DELETE /resources/[ID]
    

    REST controller tries to call a delete_[ID] method, which can't be handled. Shouldn't it call delete_index([ID])? Or maybe I'm doing something wrong? Thanks for any help!
  • According to the code of the Rest controller, it calls 'delete_resources'.
  • Could you give exact line where did you find it? I've debugged the code and it clearly calls 'delete_[ID]' method.
  • Controller_Rest, router() method, line #107.
    $controller_method = strtolower(\Input::method()) . '_' . $resource;
    

    where $resource is a parameter passed to the router method which contains the first URI segment (unless you have routing in place that messes with the URI).
  • Ok, now I understand - I had to change
    DELETE /resources/[ID]
    
    to
    DELETE /resources/resource/[ID]
    

    Resources is my REST controller, so the second URI will call delete_resource([ID]) method. However, wouldn't it be more convenient to call delete_index([ID]) when given the first URI? Calling delete_[ID] is useless.
  • How would the Rest controller know that the second URI is an ID and not an action name? If you want that, create a route for it that routes /resources/[ID] to /resources/index/[ID].

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion