-
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
2.5 - requestAction routes to wrong URL when prefixes are set. #3443
Comments
Maybe your expectation is wrong. |
The most common place to use requestAction is in an element, and elements are intended for re-use. They shouldn't be tightly coupled to the current type of request being made. An element that uses requestAction should only be coupled with the controller/action that its calling. How can an element know what current prefix is set? I've run into this issue when rendering error handlers as an example. Errors need to generate their view in a wide range of requests types. |
The issue here is that all reverse routed URLs inherit the the current prefix as the common case is generating URLs for redirects and links. A simple way around this issue is to use string URLs. Unlike 1.x, array URLs are less efficient than string URLs when used with requestAction() in 2.x. |
Thanks Mark, I didn't know strings would resolve the issue. That's good for me. I'll change my requests to use strings from now on. |
Awesome, I'm going to close this as doing deeper surgery on the Router to handle this case will probably cause more trouble than it is worth. It may also break existing apps where people want the prefix to automatically apply itself. |
Assume you have a prefix set for
json
for a controller's action calledindex
. If you use requestAction during that request it will have thejson
prefix set, and it shouldn't.Assuming you're using the default routes from CakePHP.
Example controller
Now in the view
json_index.ctp
The above will generate the error
/users/json_find
action does not exist in Users controller.This is a problem in a couple of ways. 1) The programmer has to add
'json'=>false
to all requestAction calls. 2) If the programmer adds a new prefix all requestAction calls will break if the request has it set.The text was updated successfully, but these errors were encountered: