2017-10-09 85 views
-1

在Zend框架3中,我尝试将新的控制器“ArticleController”添加到已存在的模块City中,但失败了。我张贴屏幕快照,我的文件夹结构和module.config.php。你能解释一下问题是什么?顺便提及,当访问http://0.0.0.0:7000/city在zf3中添加新的控制器到已存在的模块

访问当工作http://0.0.0.0:7000/article enter image description here enter image description here

接着,模块\城市\配置\ 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', 
     ], 
    ], 
]; 

回答

2

错误信息是明确。应用程序不知道任何关于您的控制器。您的模块配置必须在“控制器”键下有关于控制器的信息。签出zend documentation,你会在配置文件中看到“controllers”键。

+0

非常感谢您回复并抱歉,迟到回复。我尝试添加“控制器”到module.config.php,但失败了。然后,我找到了解决方案。将文章控制器的值添加到City/src/Module.php中的“工厂”中。完成zend框架教程后,我尝试追加新的控制器。教程应用“工厂”,所以它没有成功。 https://docs.zendframework.com/tutorials/getting-started/database-and-models/非常抱歉,穆罕默德。 – hikozuma

+0

我假设你的“控制器”配置就像 [“controllers”=> [“factories”=> [“MyController”=>“MyControllerFactory”]]] 这就是“controllers”配置方式。如果您的控制器没有任何依赖注入,则不需要工厂。所以你会在“invokables”键下注册它。 [“controllers”=> [“invokables”=> [“MyController”]]] –

相关问题