0

我是第一次设置 ZF3 项目,我似乎无法让路由工作。在我的主页上,我收到 404:“请求的 URL 无法通过路由匹配。”

这是我的目录结构:

目录结构的屏幕截图

我的模块.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';
    }
}

以及在 module.config.php 中的违规路由 ( 'home'):

<?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
]

4

1 回答 1

0

在使用两个模块(Home 和 Admin)时,我在两个模块'home'中都定义了一个路由。我认为'home'这只是一个魔术字符串,所有模块都需要在其路由的顶层有一个,而实际上所有模块中的所有顶层路由都必须唯一命名

我将 Admin 的顶级路由重命名为,'admin'并且路由器能够按预期将我发送到 Home 的顶级路由。

于 2020-11-30T19:02:27.073 回答