We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Micro Application Wildcard Routing

Im trying to port over a simple API from Slim and am having issues making routes that accept a variable amount of parameters. The number of parameters is unknown so I cannot hard code numerous different params. For example I have a route that can have numerous numbers of parameters:

/route/var1/var2/var3

/route/var1/var2/

/route/var7/var8/var1/var5

In Slim the syntax is:

/route/:variables+

Is there a way to do this with Phalcon micro? I noticed that the whole path is dumped into $_GET['_url'], however I would prefer not to have to parse that on not found. Thanks



98.9k
edited Jul '14

You can use the :params placeholder:

<?php

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

$app->get('/route/:params', function ($var1, $var2, $var3) {
    echo "<h1>Welcome $var1!</h1>";
});

$app->handle();

https://docs.phalcon.io/en/latest/reference/routing.html#defining-routes