dran0703 2016-11-19 23:14
浏览 132
已采纳

模块无法初始化zf3已经搜索过互联网

I'm receiving the following error in a Zend Framework 3 Application:

Fatal error: Uncaught Zend\ModuleManager\Exception\RuntimeException: Module (Serve) could not be initialized.

I'm aware that there is some answers however none seem to point to zf3 and ive already scanned them without answer. I cannot seem to find an answer through research.

Is it possible that my application is not loading modules? I have modified the application config just a tad so it might just not be loading the module itself.

I have a folder structure:

- module
   -Serve
      -src
         -Module.php
         -Controller
            -IndexController.php
      -config
         -module.config.php
      -view

I have the module added to the modules array inside /config/application.config.php.

Here is my module.config.php

namespace Serve;

return array(
        'controllers' => array(
                'invokables' => array(
                        'Serve\Controller\Index' => 'Serve\Controller\IndexController',
                ),
        ),

        // The following section is new and should be added to your file
        'router' => array(
                'routes' => array(
                        'serve' => array(
                                'type'    => 'segment',
                                'options' => array(
                                        'route'    => '/srv[/:action]',
                                        'constraints' => array(
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
                                        ),
                                        'defaults' => array(
                                                'controller' => 'Serve\Controller\Index',
                                                'action'     => 'index',
                                        ),
                                ),
                        ),
                ),
        ),

        'view_manager' => array(
                'template_path_stack' => array(
                        'album' => __DIR__ . '/../view',
                ),
                'strategies' => array(
                        'ViewJsonStrategy',
                ),
        ),
);

Here is my Serve\Module.php file:

<?php
namespace Serve;

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

I have a bunch of business logic inside my Application\Module.php however nothing that looks to disrupt loading modules.

I cannot seem to find an answer through research. What could be wrong here?

  • 写回答

1条回答 默认 最新

  • dousi6192 2016-11-23 22:12
    关注

    Did you add the module to the autoloader? https://github.com/zendframework/ZendSkeletonApplication/blob/master/composer.json#L23

    In ZF2, we used to autoload pretty much anything through the Module class, now we can just do it in composer, which is easier and allow options such as --optimize (generate classmaps) and --classmap-authoritative (do not load any class outside of the classmap).

    Don't forget to composer dumpautoload after editing the composer.json file :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败