flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.64k stars 407 forks source link

route with 2 different expressions #438

Closed oscarlosan closed 3 years ago

oscarlosan commented 3 years ago

with my previous router I had named autoroutes, 2 expressions and by get: $router->get ('/activa-([0-9]+)-([0-9a-z]+)', function ($id, $code) { } Note: parentheses shorten the route.

With Flightphp, I have put it with many combinations and it does not work: Flight::route ('/activa-@id:[0-9]+-@code:[0-9a-z]+)', function ($ id, $ code) { }

If anyone can help I would appreciate it. Thank you.

oscarlosan commented 3 years ago

is to solve this type of route: domain.com/activa-444605-45665dg5e5ew

oscarlosan commented 3 years ago

parentheses of my previous path was added ->+) excuse me. a greeting.

oscarlosan commented 3 years ago

how can i make it work with dash instead of slash? instead of: domain.com/activa-444605/45665dg5e5ew So: domain.com/activa-444605-45665dg5e5ew

work: @id:[0-9]+/@code:[0-9]+

this does not work: @id:[0-9]+-@code:[0-9]+

mikecao commented 3 years ago

The parameter names can only be used on url segments. So your url would have to be domain.com/activa/@id/@code. If you need to use dashes, then just match the entire thing and use PHP explode to break apart the string yourself.

oscarlosan commented 3 years ago

thanks