将新控制器添加到 zf3 中的现有模块
Add new controller to existed module in zf3
在 Zend Framework 3 中,我尝试将新控制器 "ArticleController" 添加到现有模块 City 但失败了。我 post 屏幕截图,我的文件夹结构和 module.config.php。你能解释一下问题是什么吗?顺便说一句,它在访问 http://0.0.0.0:7000/city
时有效
访问时http://0.0.0.0:7000/article
接下来,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',
],
],
];
错误信息明确。应用程序对您的控制器一无所知。您的模块配置必须在 "controllers" 键下包含有关控制器的信息。签出 zend documentation,您会在配置文件中看到 "controllers" 键。
在 Zend Framework 3 中,我尝试将新控制器 "ArticleController" 添加到现有模块 City 但失败了。我 post 屏幕截图,我的文件夹结构和 module.config.php。你能解释一下问题是什么吗?顺便说一句,它在访问 http://0.0.0.0:7000/city
时有效访问时http://0.0.0.0:7000/article
接下来,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',
],
],
];
错误信息明确。应用程序对您的控制器一无所知。您的模块配置必须在 "controllers" 键下包含有关控制器的信息。签出 zend documentation,您会在配置文件中看到 "controllers" 键。