开发者

Cakephp: apostrophe in URl and view cache

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.


Using PHP's urlencode() function, encode the component(s) of your URL that may contain non-alphanumeric characters before passing them into HtmlHelper::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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜