【问题标题】:Url parameters values with special characters are providing errors in view带有特殊字符的 URL 参数值在视图中提供错误
【发布时间】:2012-12-15 15:59:14
【问题描述】:

我编辑了 Url manager 以提供 SEO 友好的 url,但是当 url 的值带有特殊字符(例如 . or () or - or any other special character)时出现问题

http://localhost/nbnd/search/city/delhi

In city action
var_dump($_GET);

output: array(1) { ["city"]=> string(6) "delhi" } 

but when url is with some special character
http://localhost/nbnd/search/city/north-delhi or
http://localhost/nbnd/search/city/north.delhi or
http://localhost/nbnd/search/city/(north)delhi

In city action
var_dump($_GET);

Output : array(1) { ["north-delhi"]=> string(0) "" } 
and so for other

数组值的这种变化会导致错误。

【问题讨论】:

  • 您希望允许哪些字符?
  • @bool.dev 我想要所有它们在早期使用默认网址但它不适用于 SEO 格式的网址

标签: yii yii-components


【解决方案1】:

如果您想要各种字符,请从相关的question/answer 更改您的规则:

'<controller:\w+>/<action:\w+>/<city>'=>'<controller>/<action>',
// omit the pattern \w+ from city:\w+

Documentation:

如果省略ParamPattern,则表示参数应匹配除斜杠/之外的任何字符。

【讨论】:

    猜你喜欢
    • 2012-03-22
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    • 2018-04-26
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    相关资源
    最近更新 更多