简体   繁体   English

如何在 Zend 框架中将 URL 作为 URL 的参数传递?

[英]How do I pass a URL as a parameter of an URL in Zend Framework?

My question spawns from me sending an email to the user with something like the following:我的问题源于我向用户发送 email ,内容如下:

http://mydomain.net/login/index/dest/%2Finvitation%2Fconfirm%2Fconfirmation_key%2F15116b5e4c61e4111ade679c10b3bf27 http://mydomain.net/login/index/dest/%2Finvitation%2Fconfirm%2Fconfirmation_key%2F15116b5e4c61e4111ade679c10b3bf27

As you can see, what I'm trying to do is pass a url as the parameter "dest" so that the login page will know where to redirect after the user logs in. However, I'm presented with the following:如您所见,我要做的是传递 url 作为参数“dest”,以便登录页面知道用户登录后重定向到哪里。但是,我看到以下内容:

404 未找到 - /login/index/dest//invitation/confirm/confirmation_key/15116b5e4c61e4111ade679c10b3bf27

This is the View I use to create the email:这是我用来创建 email 的视图:

<p>
<?if($this->invitation->user):?>
<a href='<?=$this->serverUrl($this->baseUrl().$this->url(array(
    'action'=>'index',
    'controller'=>'login',
    'dest'=>$this->url(array(
        'action'=>'confirm',
        'controller'=>'invitation',
        'confirmation_key'=>$this->invitation->confirmation_key
    ))
)));?>'>Log in to confirm this invitation.</a>

//The view continues...

Any idea on how to keep this from translating the URI encoded items to their literal value would be greatly appreciated.任何关于如何防止将 URI 编码项转换为其文字值的想法将不胜感激。

Can't you just send it over as a simpel GET parameter?你不能把它作为一个简单的 GET 参数发送过来吗?

Like http://mydomain.net/login/index/?redirect=/invitation/confirm/confirmation_key/15116b5e4c61e4111ade679c10b3bf27http://mydomain.net/login/index/?redirect=/invitation/confirm/confirmation_key/15116b5e4c61e4111ade679c10b3bf27

That's how it's mostly done actually.这就是它实际上是如何完成的。

  1. What ChrisR wrote is absolutly the answer ChrisR 写的绝对是答案
  2. Why wouldn't you just use the $_SERVER['referer']你为什么不直接使用$_SERVER['referer']

You can also upgrade your link like this:您还可以像这样升级您的链接:

<a href='<?=$this->serverUrl($this->baseUrl().$this->url(array(
'action'=>'index',
'controller'=>'login',
'dest'=>base64_encode($this->url(array(
    'action'=>'confirm',
    'controller'=>'invitation',
    'confirmation_key'=>$this->invitation->confirmation_key
))))

));?>'>Log in to confirm this invitation.</a>

But on the /login/index , you will need to use the base64_decode() to get the original Not the most pretty solution, but if you are not able to use the simple querystring, this is a way, how to pass a string via URL safely.但是在/login/index上,您将需要使用base64_decode()来获取原始的不是最漂亮的解决方案,但是如果您无法使用简单的查询字符串,这是一种方法,如何通过URL 安全。

http://en.wikipedia.org/wiki/Base64 http://en.wikipedia.org/wiki/Base64

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM