-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple url for single controller #34
Comments
Hi Marco, The problem here is your regex pattern is invalid. This won't actually group the different language options into a single captured element: $r->addRoute('GET', '/{lang:(it|ch)}/blog/', 'Blog'); If you want to actually group multiple options for a single variable your regex needs to define the languages as a non-capturing group like this: $r->addRoute('GET', '/{lang:(?:it|ch)}/blog/', 'Blog'); The wrapping |
Hi, thank you very much - that's awesome. :D Regards, |
I think it would be good to check that the regex doesn't contain capturing groups. Many people aren't familiar with things like Btw, it would be enough to write |
This will make it much simplier, but also may decrease a little bit the performances? |
I've added a note about capturing groups to the readme: d651b35 |
Hi,
I would like to use the same controller for multiple urls (because I show exactly the same data, but just in different languages) and I've tried this code:
but this does not work. I get this error:
and with
$r[0] is empty, so the application does not know what is the controller to use.
I've tried to dump, in GroupCountBased, the route data inside the foreach:
just to try to understand the problem, and I've got:
so I think that the problem is related to the fact that routes is "collected" and the use of | (pipe) between multiple urls broke the original regexs.
I've workarounded it redefining urls:
but this does not satisfy me. There is a way to achieve the use of variable url parts for the same controller and at the same time to obtain from the dispatcher the first part of url (it or ch) as a variable?
Consider that I can't simply do
because this will also route the /sitemap/ url (and also any other url) and I want to avoid to serve everything with the same controller.
Thank you for reading,
Marco
The text was updated successfully, but these errors were encountered: