Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

HTTP Method Restrictions

Hi, everybody!

I have the following router:

$di->set('router', function () {
    return require ROOT . '/app/config/routes.php';
});
<?php
$router = new Phalcon\Mvc\Router();

$router->removeExtraSlashes(true);

$router->addGet('/contacts', 'Contacts::index');
$router->addGet('/contacts/show/{id}', 'Contacts::show');
$router->addPost('/contacts/store', 'Contacts::store');
$router->addPut('/contacts/update/{id}', 'Contacts::update');
$router->addDelete('/contacts/destroy/{id}', 'Contacts::destroy');

return $router;

Why HTTP Method Restrictions doesn't work? E.g. The table entry (id: 1) is being deleted after opening the page 'something/contacts/destroy/1' using my browser (GET Method). So, I have to use the following check:

if($this->request->isDelete()){
code...
}

Thanks for your help.



83.4k
Accepted
answer

Hello, you have to disable default routes:

$router = new Phalcon\Mvc\Router(false);

http://docs.phalconphp.com/en/latest/reference/routing.html#default-behavior

Hello, you have to disable default routes:

```php $router = new Phalcon\Mvc\Router(false); ```

http://docs.phalconphp.com/en/latest/reference/routing.html#default-behavior

It works perfectly. Thank you, Phalcon!