mrjgreen/phroute

Working with put and delete method

adkstar opened this issue · 1 comments

I am trying to route the PUT and DELETE method to a controller. Here is my router code:
$router->put('country/{id:\d+}',['app\controllers\Country','update']);
the same for DELETE.

the problem here is, how could I make PUT and DELETE request from html form, since html forms does not support http verbs except GET and POST. But other php frameworks implement this method by adding:

Can I use this technique in this library or if there is any other method to achieve this ???

You can dispatch the router with any method you wish, so perhaps just override the HTTP method using a custom request variable:

$method = isset($_REQUEST['_method']) ? $_REQUEST['_method'] : $_SERVER['REQUEST_METHOD'];
$dispatcher->dispatch($method, '/');