【发布时间】:2013-04-12 09:36:18
【问题描述】:
带有德语特殊字符的 URI 不起作用(错误 404)。我已经遇到过这个问题 (here),并且已经通过使用它的 unicode modifier 和 custom view helper 解决了。
现在我在 Segment 子路由上遇到了同样的问题,但这次使用 unicode 标识符和自定义视图助手的方法不起作用。
sld.tld/sport/sportäöüÄÖÜß/cityäöüÄÖÜß 或 sld.tld/sport/sportäöüÄÖÜß/cityäöüÄÖÜß/page/123 等所有请求都以 404 错误结束。
/module/Catalog/config/module.config.php
<?php
return array(
...
'router' => array(
'routes' => array(
'catalog' => array(
...
),
'city' => array(
...
),
// works correctly, if I remove the child route
'sport' => array(
'type' => 'MyNamespace\Mvc\Router\Http\UnicodeRegex',
'options' => array(
'regex' => '/catalog/(?<city>[\p{L}\p{Zs}]*)/(?<sport>[\p{L}\p{Zs}]*)',
'defaults' => array(
'controller' => 'Catalog\Controller\Catalog',
'action' => 'list-courses',
),
'spec' => '/catalog/%city%/%sport%',
),
'may_terminate' => true,
'child_routes' => array(
'courses' => array(
'type' => 'segment',
'options' => array(
'route' => '[/page/:page]',
'defaults' => array(
'controller' => 'Catalog\Controller\Catalog',
'action' => 'list-courses',
),
),
'may_terminate' => true,
),
)
),
),
),
...
);
我也尝试过使用UnicodeRegex 子路由:
'sport' => array(
'type' => 'MyNamespace\Mvc\Router\Http\UnicodeRegex',
'options' => array(
'regex' => '/catalog/(?<city>[\p{L}\p{Zs}]*)/(?<sport>[\p{L}\p{Zs}]*)',
'defaults' => array(
'controller' => 'Catalog\Controller\Catalog',
'action' => 'list-courses',
),
'spec' => '/catalog/%city%/%sport%',
),
'may_terminate' => true,
'child_routes' => array(
'courses' => array(
'type' => 'MyNamespace\Mvc\Router\Http\UnicodeRegex',
'options' => array(
'regex' => '/page/(?<page>[\p{N}]*)',
'defaults' => array(
'controller' => 'Catalog\Controller\Catalog',
'action' => 'list-courses',
),
'spec' => '/page/%page%',
),
'may_terminate' => true,
),
)
),
UnicodeRegex
见here
UnicodeSegment
扩展Zend\Mvc\Router\Http\Segment,并用u完成所有preg_match(...)调用的输入:
'((\G(?P<literal>[^:{\[\]]*)(?P<token>[:{\[\]]|$)))u''(\G\{(?P<name>[^}]+)\}:?)u''((\G(?P<name>[^:/{\[\]]+)(?:{(?P<delimiters>[^}]+)})?:?))u''(\G(?P<literal>[^}]+)\})u''(\G' . $this->regex . ')u''(^' . $this->regex . '$)u'
如何让它工作?
【问题讨论】:
-
我已经提交了这个as a bug in the ZF2 issue trackeg。在那里订阅可能有助于在上游修复此问题。
标签: php zend-framework2 http-status-code-404 zend-route zend-router