Article

Zend Framework 2 Routing for Maintainers

Debug ZF2 literal/segment routes and controller maps before and after Laminas namespace rewrites.

ZF2 routing lives in module config and resolves to controller services—not filesystem paths alone. After migration, route options that embed old controller service names are a common 404 source.

// LEGACY route
'invoice' => [
    'type' => 'segment',
    'options' => [
        'route' => '/invoice[/:id]',
        'defaults' => [
            'controller' => 'Invoice\Controller\Invoice',
            'action' => 'view',
        ],
    ],
],
// MODERN — verify controller service keys still match after migrate
'defaults' => [
    'controller' => \Invoice\Controller\InvoiceController::class,
    'action' => 'view',
],

Test every critical named route after composer install. Pair with modules and ZF2 migration.

Related tools

Related reading