将经过URL编码的URL作为参数传递给CakePHP的控制器/操作 [英] Passing an urlencoded URL as parameter to a controller / action at CakePHP

查看:434
本文介绍了将经过URL编码的URL作为参数传递给CakePHP的控制器/操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对CakePHP很新,因为这样,有一些基本的东西,我用来做Zend框架,我被蛋糕打败了。

I'm fairly new on CakePHP and because of so, there are some basic things that I used to do with Zend Framework that I'm beaten up with Cake.

我正在一个项目中,我必须传递一个命名的参数到控制器/操作。设置路由和传递参数相当简单,我的问题是当参数是一个urlencoded url。

I'm working on a project where I have to pass a named parameter to a controller / action. Setting up the route and passing the parameter is fairly simple, my problem is when the parameter is a urlencoded url.

例如: http://www.cakephp.com/controller/action/http%3A%2F%2Fwww。 google.com 不管控制器和操作设置,将抛出一个404,但通过/controller/action/http://www.google.com工作在某种程度上,唯一的问题是它标识http作为命名参数。换句话说,如果我/ /controller/action?url=http://www.google.com,它会工作。

For example: http://www.cakephp.com/controller/action/http%3A%2F%2Fwww.google.com regardless of the controller and action setup, will throw a 404, but passing /controller/action/http://www.google.com work in some way, the only problem is that it identifies the http as a named parameter. In another way, if I do /controller/action?url=http://www.google.com it will work.

我使用的工作这是将值作为base64编码字符串,但它带来一些限制。例如,如果它是一个API,没有办法,你可以保证使用API​​的系统可以编码base64一个字符串。

The work around that I had used for this is to pass the value as a base64 encoded string, but it brings some limitations. For instance, if it is an API, there is no way that you can guarantee that the system using the API can encode base64 a string.

无论如何最好的解决方案将是仍然将一个url编码的字符串传递给一个命名参数。问题是,为什么CakePHP不接受一个urlencoded字符串作为参数,为什么它抛出一个404?

Anyway the best solution would be still passing a url encoded string to a named parameter. Question is, why CakePHP does not accept a urlencoded string as a parameter and why does it throws a 404?

提前感谢所有。

推荐答案

我已经围绕这个问题添加了一个工作。前面的答案指向一个帖子实际上回答了为什么它发生和解决方案之一。发生什么情况是Apache上的.htaccess的解决方法有点危险,因为它将禁用安全标准。

I have added a work around this issue. The previous answer that pointed to a post actually answered why it was happening and one of the solutions. What happens is that the workaround for .htaccess on Apache is a bit dangerous because it will disable a security criteria.

有两种方法通过代码我使用两个):

There are 2 ways to work this out via code (and I'm using both):


  1. 将所有网址以base64编码字符串的形式发送

  2. 接受网址作为命名的参数,但是,正如你会注意到的,它将任何http://转换为http:/,因此必须正确识别这种情况,然后才纠正字符串。

这不是一个美丽的解决方案,但它绝对是一个实用的。

It is far from being a beautiful solution, but it is definitely a practical one.

这篇关于将经过URL编码的URL作为参数传递给CakePHP的控制器/操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆