Symfony2路由要求:如何启用UTF-8模式? [英] Symfony2 Routing Requirements: how to enable UTF-8 mode?
问题描述
我想使用以下正则表达式作为symfony2路由的要求:
I want to use the following regex as an requirement for symfony2 routing:
/^[ \x{00C0}-\x{01FF}a-zA-Z'\-]+$/u
这里的特别之处是启用带有u-修饰符的utf8模式.如何将此/u传递到symfony routing.yml的需求部分?
The special thing here is to enable the utf8-mode with the u-modifier at the end. How to pass this /u to requirement-section of a symfony routing.yml?
我们当前的routing.yml如下所示:
Our current routing.yml looks like that:
search_by_name:
path: /search/name/{name}-4/{page}/{limit}
defaults: { _controller: SearchBundle:SearchByName:index, page: 0, limit: 8 }
requirements:
name: "[äüößÄÖÜ´\"`èéa-zA-Z\-]+"
现在我们要应用上述模式:
Now we want to apply the pattern mentioned above:
requirements:
name: "[ \x{00C0}-\x{01FF}a-zA-Z'\-]+" <-- "u" is missing
在哪里传递"u"?仅在末尾添加字符会导致以下错误:
Where to pass the "u"? Just adding the character at the end will result in the following error:
警告:preg_match():编译失败:\ x {...}中的字符值 序列在偏移量61处太大
Warning: preg_match(): Compilation failed: character value in \x{...} sequence is too large at offset 61
推荐答案
Symfony Routing组件不完全支持Unicode;基本上是因为它在内部不使用多字节安全的字符串函数.使用此类标志时,可能会发生意外问题.
The Symfony Routing component doesn't support fully Unicode ; basically because it doesn't use multibyte-safe string functions internally. Unexpected issues can occurs when using such flags.
该组件在Unicode支持方面的进展在以下问题中得到跟踪: https://github.com. com/symfony/symfony/issues/5236
Progress in Unicode support in the component is tracked in the following issue: https://github.com/symfony/symfony/issues/5236
这篇关于Symfony2路由要求:如何启用UTF-8模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!