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



我已经编辑了 Url 管理器以提供 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

数组值的此更改会导致错误。

由于您想要各种字符,请从相关的问题/答案更改规则:

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

文档:

如果省略了 ParamPattern,则意味着参数应匹配除斜杠/以外的任何字符。

最新更新