I have an app that uses several prefixes and, while not frequent, it’s also not unusual to add a prefix as we go along. What makes this painful is that the Router::url() method, by default, assumes that any url built should inherit the prefix of the current page if no prefix is explicitly specified.
This appears to be a very deliberate action so I’m assuming that the majority of folks find it more useful than not, but I find it much more readable/maintainable to simply construct my URLs with prefixes where the URL needs one and leave it off when it doesn’t. Long ago, I created AppHelper::url() to override Helper::url() which assumes nothing and only builds a URL with a prefix when it’s explicitly requested and that’s a huge help for links generated in views.
There is, however, another scenario that I’d like to override and haven’t found a “clean” way to go about it. Consider an unauthenticated user who’s bookmarked a link to an admin resource (e.g. /admin/thing_that_needs_to_be_administered/some_action). S/he clicks that bookmark, but isn’t logged in so s/he gets redirected. Instead of being redirected to /users/login, s/he’s sent to /admin/users/login which doesn’t exist. Whoops.
Has anyone else found a way of doing this that they really like? The idea is to not have to explicitly set each prefix to false everywhere that redirection is done. That is just way too much maintenance when a prefix is added.
I think this gets easier in Cake 2, but we’re running on Cake 1.3.
Any thoughts would be much appreciated.
I would suggest trying this route if you have not already:
EDIT: Sorry, loginAction
That will explicitly set the login url.