salmiak Posted September 17, 2020 Share Posted September 17, 2020 I'm trying to get the last url segment with the new API and when I try to access the last segment I get the one second to last. For example in the url: https://domain.com/page/seg1/seg2/seg3/seg4/ $input->urlSegment(-1) and $input->urlSegmentLast return "seg3" $input->urlSegment(-2) returns "seg2" $input->urlSegment(-3) returns "seg1" as expected: $input->urlSegment(1) returns "seg1" $input->urlSegment(4) returns "seg4" I tried the following $input->urlSegment(0) returns "seg1" $input->urlSegment(-0) returns "seg1" What's going wrong here? I'm using ProcessWire: 3.0.165 Link to comment Share on other sites More sharing options...
Robin S Posted September 17, 2020 Share Posted September 17, 2020 2 hours ago, salmiak said: What's going wrong here? It's a bug - please open an issue on GitHub to bring it to Ryan's attention. The URL segments array has a 1-based index but this is lost to a 0-based index when the array is reversed here: https://github.com/processwire/processwire/blob/ee4c46a442f09cf81f9e1800c5fdfcd1176f538a/wire/core/WireInput.php#L576 As a workaround for now you could do this: $segments = $input->urlSegments; $last_segment = end($segments); 2 Link to comment Share on other sites More sharing options...
salmiak Posted September 17, 2020 Author Share Posted September 17, 2020 Thanks! I can work around it for now. Issue opened: https://github.com/processwire/processwire-issues/issues/1247 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now