我在vendor / data-table中的via composer中加载了一个自定义模块。
虽然我认为我已正确设置所有内容,但我收到以下错误:
PHP致命错误:无法初始化消息'模块(MJErwin \ DataTable)的未捕获异常'Zend \ ModuleManager \ Exception \ RuntimeException'。在/Applications/MAMP/htdocs/rota/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:189
如果我从application.config.php中删除MJErwin \ DataTable,一切正常,所以它似乎是模块本身的问题。
结构如下:
我的Module.php:
namespace MJErwin\DataTable;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
class Module implements ConfigProviderInterface
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return [
'Zend\Loader\StandardAutoloader' => [
'namespaces' => [
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
],
],
];
}
}
module.config.php:
return [
'view_manager' => [
'template_path_stack' => [
__DIR__ . '/../view',
],
],
];
然后在application.config.php中:
<?php
/**
* Configuration file generated by ZFTool
* The previous configuration file is stored in application.config.old
*
* @see https://github.com/zendframework/ZFTool
// */
return [
'modules' => [
'Application',
'MJErwin\\DataTable',
'DoctrineModule',
'DoctrineORMModule',
'Environment',
'ZendDeveloperTools',
'ZfcTwig',
'ZfcBase',
'ZfcUser',
'ZfcUserDoctrineORM',
'Navigation'
],
'module_listener_options' => [
'module_paths' => [
'./module',
'./vendor'
],
'config_glob_paths' => [
'config/autoload/{,*.}{global,local}.php'
]
],
];
答案 0 :(得分:0)
我认为有两种可能性。
首先,您手动安装了模块,在这种情况下,zf2模块加载器将查看以下路径:modules/MJErwin/DataTable/Module.php
或vendor/MJErwin/DataTable/Module.php
其他可能性是您通过composer安装模块,但忘了将Module类添加到composer.json自动加载部分
"autoload": {
"psr-0": {
"MJErwin\\DataTable": "src/"
},
"classmap": [
"./Module.php"
]
}