I am encountering an issue where the route parameter in my Mezzio application seems to be causing errors due to unintended translation behavior.
Here is my route configuration for editing a Locale
:
// Edit Locale Route
[
'name' => 'web.locales.edit',
'path' => '/locales/edit/{id:\d+}',
'middleware' => [
Mezzio\Session\SessionMiddleware::class,
Mezzio\Csrf\CsrfMiddleware::class,
\Web\Locales\LocalesEditHandler::class,
],
'allowed_methods' => ['GET', 'POST'],
],
The problem occurs when the {id}
parameter is included in the route path. Specifically:
- If I change the route to
/locales/edit
(without{id}
), the route works fine. - When
{id}
is added as a dynamic segment, I encounter an error: “No Translator provided”.
I am using:
- Mezzio with Laminas\Router (and Laminas\I18n installed)
- Dynamic route matching with
Segment
type - Translator is configured (likely through Laminas\I18n)
What I’ve Tried:
- I ensured that the route itself does not include translatable content.
- I tested removing Laminas\I18n entirely, but the problem persisted.
- I attempted switching to the
Literal
route type instead ofSegment
, but this doesn’t solve the issue sinceLiteral
routes do not support dynamic parameters.
Questions:
- Is there a way to prevent the translator from affecting the route parameters like
{id}
? - Is this a configuration issue with Laminas\I18n or the router setup?
- How can I explicitly disable translation for a specific route or ensure dynamic segments like
{id}
are treated as plain route parameters?
Environment:
- Mezzio: 3.x
- Laminas\Router: Latest
- Laminas\I18n: Installed
- PHP: 8.1.x
Any guidance on how to resolve this issue or prevent the translator from interfering with dynamic route parameters would be greatly appreciated. Thank you!