Cakephp:URl 中的撇号和视图缓存
如果 URL 中包含撇号,我会遇到缓存问题。
例如: www.example.com/controller/action/What's+My+Name
在第一次加载时,当缓存不存在时,它加载正常。然而,一旦 创建缓存后,页面的后续加载会导致 PHP 语法 错误,因为在缓存文件中有一行:
$controller->here = $this->here = '/controller/action/What's My Name?';
请注意,撇号未转义,因此会出现 PHP 语法错误。
我该如何解决这个问题?这被认为是 Cake 中的错误吗?
谢谢。
I am having a problem with cache if the URL has apostrophe in it.
For example:
www.example.com/controller/action/What's+My+Name
On first load when cache isn't there, it loads fine. However, once the
cache is created, the subsequent load of the page causes PHP syntax
error because in the cache file there is a line:
$controller->here = $this->here = '/controller/action/What's My Name?';
Note the apostrophe isn't escaped and hence the PHP syntax error.
How can I fix this? Is this considered a bug in Cake?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 PHP 的
urlencode()
函数,对可能包含非字母数字字符的 URL 组件进行编码,然后将其传递到HtmlHelper::link
或其他内容中你。您可能还需要考虑一个更大的问题,即首先在 URL 中包含非字母数字是否是一个好主意,这样做是否确实满足了需要。
Using PHP's
urlencode()
function, encode the component(s) of your URL that may contain non-alphanumeric characters before passing them intoHtmlHelper::link
or what-have-you.You may also want to consider the larger issue of whether it's a good idea to have non-alphanumerics in your URLs in the first place, whether there's a real need served by doing so.
回到最初的答案 - 您生成了无效的 URL,并以某种方式期望框架不会破坏?
要么在服务器端转义它们 (urlencode),要么为 url 生成一个 slug。
像您所做的那样滥用 url 显然会产生不一致的结果 - 客户端和 CakePHP 端。这不是一个模棱两可的案例——你做错了。
Back to the original answer - You generate invalid URL's and somehow expect the framework to not break?
Either escape them (urlencode) server side or generate a slug for the url.
Abusing the url like you are doing is flat out going to give inconsistent results - client side and CakePHP side. This is not an ambiguous case - you are doing it wrong.