Hey!
I'm currently writing an API (Phalcon Micro, version 3.4) that is versioned. That means, my routes look something like this: e.g. /2.1/my/application/exampleuser
or with parameters: /{version}/my/application/{username}
These parameters are automatically passed to the Controller::Action Method by Phalcon. So my Controller / Action for beforementioned route looks like this:
class ExampleController extends \Phalcon\Di\Injectable
{
public function userAction(int $version, string $username)
{
// my code here
}
}
Now, I really don't want to add the version parameter to every single action. What I would like to do is to add a Middleware (e.g. hook into the micro:beforeExecuteRoute
Event), get the version from the parameters and remove that route parameter so my userAction
will look like this instead:
public function userAction(string $username)
{
// my code here
}
What I already tried is to modify the parameter list via the dispatcher:$application->dispatcher->setParams($modifiedParams);
but without any success. The parameters for this also seem to be only available within the controller itself and not in the middleware.
I would like to know how I can achieve what I want. Can this be done with Phalcon itself, or do I have to write some kind of a script to do so (or tweak nginx configuration)?
If there's any information missing, let me know.