daveh / php-mvc

A simple PHP model-view-controller framework, built step-by-step as part of the "Write PHP like a pro: build an MVC framework from scratch" course on Udemy.
https://davehollingworth.com/go/phpmvc/
MIT License
782 stars 311 forks source link

url problem #103

Closed ianims closed 2 years ago

ianims commented 2 years ago

I am trying to add urls with the following form: site.com/process/view/345/some_text site.com/process/view/876/some_other_text

so the last two parameters vary.I have tried: $r->add( 'process/{action}/{id:}/{lang:[a-z]{2}+}') and also : $r->add( 'process/{action}/{id:}/{name:}') but it always seems to fail at the preg_match

thanks

daveh commented 2 years ago

You need a regex that includes an underscore to match those segments (plus your id variable is missing the regex). Try this:

$r->add( 'process/{action}/{id:\d+}/{name:[a-z_]+}')

ianims commented 2 years ago

ok now working ok thanks