Module cannot be initialized zf3 already searched internet

纵然是瞬间 提交于 2019-12-12 17:26:48

问题


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:


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 :)



来源:https://stackoverflow.com/questions/40698939/module-cannot-be-initialized-zf3-already-searched-internet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!