首页 文章

在zf3中将新控制器添加到现有模块

提问于
浏览
0

在Zend框架3中,我尝试将新控制器"ArticleController"添加到现有模块City但失败了 . 我发布了屏幕截图,我的文件夹结构和module.config.php . 你能解释一下问题是什么吗?顺便说一句,它在访问http://0.0.0.0:7000/city时有效

访问时http://0.0.0.0:7000/article
enter image description here

enter image description here

接下来,module \ city \ config \ module.config.php代码如下:

<?php

namespace City;

use Zend\Router\Http\Segment;

return [
    'router' => [
        'routes' => [
            'city' => [
                'type'    => Segment::class,
                'options' => [
                    'route' => '/city[/:action[/:id]]',
                    'constraints' => [
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ],
                    'defaults' => [
                        'controller' => Controller\CityController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'article' => [
                'type'    => Segment::class,
                'options' => [
                    'route' => '/article[/:action[/:id]]',
                    'constraints' => [
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ],
                    'defaults' => [
                        'controller' => Controller\ArticleController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
        ],
    ],

    'view_manager' => [
        'template_path_stack' => [
            'city' => __DIR__ . '/../view',
        ],
    ],
];

1 回答

  • 2

    错误消息很明确 . 应用程序对您的控制器一无所知 . 您的模块配置必须包含有关"controllers"键下控制器的信息 . 结帐zend documentation,您将在配置文件中看到"controllers"键 .

相关问题