Routing group REST API


I am currently developing a REST API with Phalcon and i have a doubt about group routing. So my project now is like :

$app = new Phalcon\Mvc\Micro();

$app->get('/products', function () {

$app->get('/products/{id}', function ($id) {


To avoid repeting /products, i red about group and i don't quite figured out the true meaning and i want to do something like :

 $app->group('/products', function() use($app) {

function requestProducts($app)
$app->get('/', function () {

 $app->get('/id/:id/', function ($id) {
    //other stuff

Can anyone help me around here?

Best regards.


I believe the function you are looking for is collection.

what you want to do is.

class ProductController extends \Phalcon\Mvc\Controller { public function indexAction() { //handles with/without id } }

$app = new Phalcon\Mvc\Micro(); $collection = new Phalcon\Mvc\Micro\Collection(); $collection->setHandler(new ProductController()); $collection->get('/product/{id}', 'index'); $app->mount($collection);