-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Accessing and modifying the current route #13661
Comments
Have you tried using the Uri object, it can return the path in isolation. // Get the path (without subdirectory)
$request->getUri()->getPath(); Which can then be used with any of the helpers to get paths to the current URL. |
if you use |
This seems like a bug / oversight. |
Closing as The main culprit here is the router feature which turns any extra key in URL array into query string param. This has already been changed in 4.x. |
Thank you all :) |
For CakePHP version 3.7.9
There is, afaik, currently no easy way to access current route and array of attributes, that matched the route
What is known (accessing current route/url build params):
getRequestTarget()
returns only string representation (including query and without hash url params)Cake\Routing\Router::reverseToArray($this->request)
will return array of params to build the url, however including params not contained in current url (such as _csrfToken, isAjax)build()
used like$this->Url->build(Router::reverseToArray($this->request))
will return url as string, but containing _csrfToken as get query param (see point above)Cake\Routing\Router::parseRequest($this->request)
will return relevant array of params to build array, but including_matchedRoute
What is known (building new url based on current one, given that ':lang' is recognized route segment)
$this->Url->build(['lang'=>'fr'] + Router::reverseToArray($this->request))
will generate url that contains additional data (eg. _csrfToken)$this->Url->build(['lang'=>'fr'] + Router::parseRequest($this->request))
will generate url that contains additional data (eg. _matchedRoute)Since there is always some extra data in the returned, developer cannot be sure, that even manually filtering values that are apparent, will filter out all the extra data, that could appear (ie. it is not known if the data in reverseToArray, parseRequest and others will not contain more unnecessary attributes under different circumstances)
So what I'm seeking is documentation update or API update, that would provide clear way of
The text was updated successfully, but these errors were encountered: