I'm setting up a Phalcon app using the Micro class. I'm setting up my router to use the Collection class so that I can use a controller to split up the functionality and keep it fairly contained.
Now, what I'd like to do is have a route that handles both GET and POST. With the normal micro app setup it looks pretty easy with $app->add(…)->via(['GET', 'POST']);
. However, the collections class offers a map
method but nothing like a via
.
Does anyone know the best way to achieve what I'm trying to do? Code in the router looks simply like:
<?php
use Phalcon\Mvc\Micro\Collection;
$login = new Collection();
$login->setHandler('Service\Controllers\LoginController', true);
$login->setPrefix('/login');
$login->post('/basic', 'usernameAction');
$login->map('/social/{oauthProvider}', 'socialAction')->via(['GET', 'POST']);
$app->mount($login);
(NB: this is just an included file, so auto-loading, defining $app
and so on if fine, just in another file. It also includes the map/via combination that doesn't work just to highlight what I'm trying to do.)
Thanks!
It turns out that up to 3.2 of Phalcon (which I'm using) it's can't be done as I detailed above. A
mapVia
method has been added to 3.3.x.See further details from the Phalcon forums where I also asked this question.