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 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页