2

I have the following link:

$this->Html->link('admin',array('admin'=>true,'controller'=>'users','action'=>'login','?'=>array('continue'=>$this->here)))

Which should produce a link like: http://domain.com/admin/login?continue=/location

However it always escapes the / so I get a link like: http://domain.com/admin/login?continue=%2Flocation

How do I stop this? I tried array('escape'=>false) in the link but that only escapes the link itself rather than the href.

6
  • may I ask why you use _GET params instead of named params? from the looks of your domain mod_rewrite is available on your system. that'd save you a lot of trouble. Commented Nov 5, 2011 at 16:25
  • Wouldn't it look odd if I did: http://domain.com/admin/login/continue:/location Commented Nov 5, 2011 at 16:29
  • well, passing any special characters to an url always looks odd. base64encode or at least url_encode is the least you should do then to get a valid url (which cake does here for you). you can always "undo" the encoding afterwards. Commented Nov 5, 2011 at 16:45
  • Could you show what you mean? I'd prefer to use GET params as it's the standard way of doing things like this BUT I don't want it escaping the / Commented Nov 5, 2011 at 16:49
  • Nothing to do with Cake; it's standard behaviour as far as I'm aware. Wordpress does the same (encodes the slashes) when logging in and redirecting. Not sure if it's browser specific or language specific but I don't believe there's a solution. It's purely aesthetic anyway so is it really worth worrying about. See this thread for further discussion. Commented Nov 6, 2011 at 16:33

1 Answer 1

0

You either need to manually add this part to the url after it went through cake:

$this->Html->url(...).'?continue=/location'

which I don't recommend (likely invalid url!)

or you use url_decode() in the target action to receive the correct string again (should cake usually do automatically, as well). check what the $this->request->params[named][location] key contains:

array('admin'=>true,'controller'=>'users','action'=>'login','continue'=>$this->here)

ops. in 1.3 it is still $this->params[named][location] !

Sign up to request clarification or add additional context in comments.

3 Comments

So what do I write for my Html link to do it then? As I still don't properly follow...
As I already pointed out - it SHOULD encode it. otherwise it is part of the url. and you obviously want to pass it as "content". and as such it has to be encoded. either cake style (solution above) or base64encoded.
I've seen it NOT encoded in urls so it's perfectly plausible and possible to have a url passed as content and not encoded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.