-
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
Bug: route_to() does not return relative part of the path #2971
Comments
Maybe it's referenced wrong in the documentation or it should return an absolute url like base_url does. But it should not remove / as it won't work for most people. Generally people don't develop applications in sub-folders. If you are on this url and use route_to('login') with suggested fix. You will get: Instead of: (or with baseUrl) |
If you have an app in subfolder, you always must use base-tag to set the base link (forgot to mention that) OR use absolute links/paths. Either way, "proper" As for "generally people don't develop applications in sub-folders" - if something generally is not a bug/issue, does not change the fact that it is one. I am not saying that it HAS to be changed, but I see it as a bug (at least doc-bug) and am suggesting that change. In the end, that's decision for dev team to make. I can understand that |
I didn't say it wasn't a bug, I'm saying that we should not remove /. As that will create more issues than the current behavior. We need to append baseUrl or leave it as it, but it will work for most people to append baseUrl. If it weren't intended to work this way to begin with. Then it's a documentation problem. |
Removing In most cases (when we don't host a website in a sub-folder) it's convenient to use |
It is recommended to use |
Yes, it would, but at the same time, I see no reason to stop using my fixed helper function that actually returns what route_to originally was meant to return ( prefixing original route_to with a dot is all that had to be done). Fun thing is, that I came back here because those (url related, base_url among them) helper functions changed. I wasn't updating the "engine" for quite some time. I did so now, as I have to write some new stuff for my project, jumping from 4.0.x to 4.3.x. Suddenly addresses got messed up, because functions that had to remain unchanged, as that would be a breaking change, suddenly changed … not to mention, that functions' purpose changed as well. |
The following two lines are not the same. <a href="/login">
<a href="./login"> So if we change the behavior of The framework function behavior may be changed because of bug fixes. |
Describe the bug
route_to()
helper function according to docs:While the generated path is not relative but "rooted" (I am not sure how it's called properly). If used in views, e.g. to build links/anchors, those will be relative to domain, not to base_url.
CodeIgniter 4 version
4.0.3 - current release
Affected module(s)
Routes or user-guide/docs
Expected behavior, and steps to reproduce if appropriate
Let's consider this example:
example page in service: example.com/ci-blog/login
base url: example.com/ci-blog/
url to the page relative to base url: login
route_to
returns: /loginwhich points to: example.com/login
Expected behavior -
route_to
to return parts of path relative to base_url, i.e. without slash at the beginning.Current workaround for CI user is to add dot at the beginning of every link generated by
route_to
or remove slash manually.Context
The text was updated successfully, but these errors were encountered: