Les URI avec des caractères spéciaux allemands ne fonctionnent pas (erreur 404). J'ai déjà eu ce problème (here) et il a été résolu avec le unicode modifier et un custom view helper, qui l'utilise.Les caractères spéciaux ne sont pas analysés correctement dans Zend Framework 2
Maintenant, j'ai le même problème avec une route enfant Segment
, mais cette fois l'approche avec l'identificateur unicode et une aide de vue personnalisée ne fonctionne pas.
Toutes les demandes comme sld.tld/sport/sportäöüÄÖÜß/cityäöüÄÖÜß
ou sld.tld/sport/sportäöüÄÖÜß/cityäöüÄÖÜß/page/123
se terminent par une erreur 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,
),
)
),
),
),
...
);
J'ai aussi essayé avec un itinéraire enfant 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
voir here
UnicodeSegment
Prolonge Zend\Mvc\Router\Http\Segment
et complète l'entrée de tous les appels preg_match(...)
avec u
:
'((\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'
Comment le faire fonctionner?
J'ai déposé ce [comme un bug dans le numéro ZF2 trackeg] (https://github.com/zendframework/zf2/issues/7335). Un abonnement là-bas pourrait aider à corriger cela en amont. – Caleb