具有特殊字符的Url参数值在视图中提供错误

时间:2012-12-15 15:59:15

标签: yii yii-components

我已经修改了Url管理器以提供SEO友好的网址,但是当网址包含. 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

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

1 个答案:

答案 0 :(得分:2)

如果您想要各种各样的字符,请从相关的question/answer

更改您的规则
'<controller:\w+>/<action:\w+>/<city>'=>'<controller>/<action>',
// omit the pattern \w+ from city:\w+

Documentation

  

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