PhalconPHP - Groups of Routes

205 Views Asked by At

I am using Phalcon Framework and would like to learn how to group routes. The official documentation did not help me that much.

This is how my routes look like:

$app->get('/users', function() {
   // do something
});

$app->get('/users/{id}', function($id) {
   // do something
});

$app->post('/users', function() {
   // do something
});

I would like to group these routes under "users" group so the code will be more clear and structured.

How can I do it?

1

There are 1 best solutions below

5
On

I'm use collection to this. Code look something like.

$inbound = new Phalcon\Mvc\Micro\Collection();
$inbound->setHandler('InboundController', true);
$inbound->setPrefix('/v1/inbound');
$inbound->get('/{req_no}', 'readAction');
$inbound->post('/', 'createAction');
$inbound->put('/{req_no}', 'updateAction');
$inbound->delete('/{req_no}', 'deleteAction');