-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
URI segments passed in as method parameters skips segments with value as 0 (zero) #2032
Comments
Each section of the path between the slashes is a single segment. The URI class provides a simple way to determine what the values of the segments are. The segments start at 1 being the furthest left of the path. |
Sorry if my question was not clear. I understand how segments work. My issue is that if the value of a segment is 0, then that value is not passed to the controller as a method parameter and the next segment if any is passed instead. The example I've given in the bug report illustrates the problem. I've edited the issue to try and make it a bit more clear... |
So i've tracked down why this happens and the following line is where the 0 valued segments are filtered out: CodeIgniter4/system/Router/Router.php Line 571 in 230c2ab
This line will filter out any values that evaluate to FALSE. So |
Zero params should be passed through when routing. Fixes #2032
Describe the bug
URI segments passed in as method parameters doesn't seem to work as expected if the segment contains 0 (integer zero).
CodeIgniter 4 version
4.0.0-beta3
Affected module(s)
Controllers & Routing
Expected behavior, and steps to reproduce if appropriate
If the URI segment contains zero as it's value, the segment is skipped when passed in as the method parameter.
If the URL called is something like
test/segmentTest/0/abc
, (notice the third segment is zero, so$param1
should be set as0
)but the result was:
whereas I was expecting something like:
Is this intentional? I couldn't find anything in the documentation. There are multiple situations where passing in 0 as the url param is valid.
Also please note that if no default values are given for the parameters, an error is encountered:
Context
The text was updated successfully, but these errors were encountered: