-
Notifications
You must be signed in to change notification settings - Fork 49
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
Routing: Catch-all #44
Comments
In the first method, isn't a single wildcard enough? => |
No, as the single wildcard will take precedence over any single level routes. E.g. $f3->route('GET|HEAD|POST /', 'Home->controller');
$f3->route('GET|HEAD|POST /@action', 'Home->@action');
// wildcard will take precedence over the two routes above
$f3->route('GET|HEAD|POST /*', 'Home->catchAll'); |
You're right. I didn't expect that behaviour. I wonder if it is intended or if it is a bug.. |
Well the doc says:
|
On my sites I use something like this |
I feel a sub-section within routing should be devoted to displaying the correct way to provide a catch-all... Fat-Free doesn't provide a direct method for catch-all, so it may confuse new users. It's also one of the first things I do within a project to provide custom logic instead of a default 405.
Now personally I have two ways of achieving this, but I figured I'd ask everyone else to see if you guys have your own ways.
Method 1:
In my tests, "//" proved to work but I didn't use a full test suite with edge cases, so I'm unsure if it provides true catch-all support.
Using "//" also infers that a method has already caught all single parameter routes. E.g.
/@action
. With this said the wildcard may need to be at a proportional depth compared with existing routes.Method 2:
I'm going to be lazy here, but it involves adding a custom error handler to catch 405 errors... I'll just provide an example from my error handler:
That's about it. Let me know your thoughts, or if you have an alternative method (we can pick which one is best suited) :)
The text was updated successfully, but these errors were encountered: