1

I've just started trying out Phalcon Micro for my RestAPI's.

Everything is working well, however I can't seem to figure out how to secure some routes, but not others.

Has anyone had any experience in this area? - I've come from Slim where I can just pass functions in the actual route definitions.

Cheers,

Ben

Nikolay Mihaylov
  • 3,868
  • 8
  • 27
  • 32
Ben Kilah
  • 3,445
  • 9
  • 44
  • 56

2 Answers2

0

Here is one way to achieve this, you can use beforeMatch() on your route, as you are used to with Slim.

$router->add('/koshnitsa', 'Basket::index')->setName('basket')->beforeMatch(
    function ($uri, $route) {
        // Replace with your conditions
        if ($https) {
            return true;
        }
        return false;
    }
);

You can even make your own filter, read more in the docs.

Nikolay Mihaylov
  • 3,868
  • 8
  • 27
  • 32
0

Also you can use more generic approach with events or middleware:

https://docs.phalconphp.com/en/3.0.0/reference/micro.html#micro-application-events https://docs.phalconphp.com/en/3.0.0/reference/micro.html#middleware-events

Juri
  • 1,369
  • 10
  • 16