无法初始化模块zf3已在Internet上搜索 [英] Module cannot be initialized zf3 already searched internet
问题描述
我在 Zend Framework 3应用程序中收到以下错误:
致命错误:未捕获的Zend \ ModuleManager \ Exception \ RuntimeException:无法初始化模块(服务).
Fatal error: Uncaught Zend\ModuleManager\Exception\RuntimeException: Module (Serve) could not be initialized.
我知道有一些答案,但是似乎没有答案指向zf3,而我已经扫描了它们而没有答案.我似乎无法通过研究找到答案.
我的应用程序是否可能未加载模块?我只是稍稍修改了应用程序配置,所以可能只是不加载模块本身.
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.
我有一个文件夹结构:
- module
-Serve
-src
-Module.php
-Controller
-IndexController.php
-config
-module.config.php
-view
我已将模块添加到/config/application.config.php
内部的模块数组中.
I have the module added to the modules array inside /config/application.config.php
.
这是我的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',
),
),
);
这是我的Serve\Module.php
文件:
<?php
namespace Serve;
class Module
{
public function getConfig()
{
return include __DIR__ . '/../config/module.config.php';
}
}
我的Application\Module.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?
推荐答案
您是否已将模块添加到自动加载器中? https://github.com/zendframework/ZendSkeletonApplication/blob/master/composer .json#L23
Did you add the module to the autoloader? https://github.com/zendframework/ZendSkeletonApplication/blob/master/composer.json#L23
在ZF2中,我们过去通常通过Module类自动加载几乎所有内容,现在我们可以在composer中完成此操作,这更容易了,并允许--optimize(生成类图)和--classmap-authoritative(做不会在类映射之外加载任何类.
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).
在编辑composer.json文件之后,别忘了编写作曲家的转储自动加载:)
Don't forget to composer dumpautoload after editing the composer.json file :)
这篇关于无法初始化模块zf3已在Internet上搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!