routeshttp-status-code-404url-routingzend-framework3laminas

ZF3: The requested URL could not be matched by routing


I'm setting up a ZF3 project for the first time, and I can't seem to get routing to work. On my homepage, I'm getting 404: "The requested URL could not be matched by routing."

Here's my directory structure:

Screen capture of directory structure

My Module.php:

<?php
namespace Home;

use Laminas\ModuleManager\Feature\AutoloaderProviderInterface;
use Laminas\ModuleManager\Feature\ConfigProviderInterface;

class Module implements AutoloaderProviderInterface, ConfigProviderInterface
{
    public function getAutoloaderConfig()
    {
        return [
            'Zend\Loader\StandardAutoloader' => [
                'namespaces' => [
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ],
            ],
        ];
    }

    public function getConfig()
    {
        return include __DIR__ . '/../config/module.config.php';
    }
}

And the offending route ('home'), in module.config.php:

<?php
namespace Home;

return [
    'router' => [
        'routes' => [
            'home' => [
                'type' => 'Literal',
                'options' => [
                    'route' => '/',
                    'defaults' => [
                        'controller' => Controller\SkeletonController::class,
                        'action' => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    // You can place additional routes that match under the
                    // route defined above here.
                ],
            ],
        ],
    ],
    ... // Other stuff
]


Solution

  • While using two modules (Home and Admin), I had a 'home' route defined in both. I thought 'home' was just a magic string and that all modules needed one at the top level of their routes, when in reality all top-level routes across all modules must be uniquely named.

    I renamed Admin's top-level route to 'admin' and the router was able to send me to Home's top-level, as intended.