-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Enable HTTP Verb in Routing #2712
Conversation
Using array for HTTP Verb e.g: $route['(:any)']['POST'] = "controller/post_method"; $route['path']['GET'] = "controller/path_get_method"; $route['path']['(:any)'] = "controller/path_any_method"; Using (:any) or not will make same result e.g: $route['path']['(:any)'] == $route['path'] So it won't break existing route
// Is there a literal match? If so we're done | ||
if (isset($this->routes[$uri]) && is_string($this->routes[$uri])) | ||
if (isset($this->routes[$uri][$http_verb])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should first check if $this->routes[$uri]
exists and then have the other conditions depending on it, i.e.:
if (isset($this->routes[$uri]))
{
if (is_string($this->routes[$uri]))
{
// regular route code
}
elseif (is_array($this->routes[$uri]) && isset($this->routes[$uri][$http_verb]))
{
// verb route code
}
...
}
Also, this feature requires proper documentation and a changelog entry. |
Thanks for your feedback. Sorry, should've read that more thoroughly. Actually I'll try fixing my code and give more proper documentation |
I was wondering if things can be done in the other way around. I mean, put them like this
This way, it will be easy to target in code. plus if plan to merge with this reverse route method with some modification, things will go nicely. Also any additions can be done easily I think. I'm using that reverse route in one of my application i'm developing. With changes to the index keys to string, I can check which controller it wants to use and get its alias name.
I believe this is one of the main feature of CI3. #218 . Isn't It? |
No, this wouldn't be convenient in terms of usage. And no, reverse routing isn't a "main" feature, it's a non-existent feature. The tag on that issue just says that it's a feature request. Ignore it, even if it gets implemented at some point we don't need to worry about it now. |
Fix code style, removed (:any) rule in http verb to avoid confusion, and add proposed documentation and changelog
I use the Pigeon library to handle this. Perhaps that can be integrated? I find it's hierarchical routes rather useful. https://github.com/jamierumbelow/pigeon |
Using array in
config/routes.php
for HTTP Verb. HTTP Verb is case-insensitivee.g:
$route['(:any)']['POST'] = "controller/any_post_method";
$route['path']['get'] = "controller/path_get_method";
$route['path']['(:any)'] = "controller/path_any_method";
Using
(:any)
or not using http verb at all will produce same resulte.g:
$route['path']['(:any)']
is the same as$route['path']
So it won't break any existing routes