Zend Framework 2:未捕获的异常 - 无法初始化模块

Zend Framework 2: Uncaught Exception - Module can't be initialized

我刚开始使用 ZF2,运行 遇到了在本地设置我需要处理的第一个项目的问题。我已经完成并在本地设置应用程序,但是当我尝试访问主页时,我收到以下异常错误:

Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (Application) could not be initialized.' in /var/www/myproject/vendor/ZF2/library/Zend/ModuleManager/ModuleManager.php on line 140

Zend\ModuleManager\Exception\RuntimeException: Module (Application) could not be initialized. in /var/www/myproject/vendor/ZF2/library/Zend/ModuleManager/ModuleManager.php on line 140

调用堆栈跟踪中还回显了一些输出。不确定它是否有助于解决此问题:

getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); $this->initDatabase($e); } public function initDatabase($e) { Feature\GlobalAdapterFeature::setStaticAdapter($e->getApplication()->getServiceManager()->get('Zend\Db\Adapter\Adapter')); } public function getConfig() { return include __DIR__ . '/config/module.config.php'; } public function getServiceConfig() { return array( 'factories' => array( 'dbadapter' => new Zfe\Factory('db'), ), ); } public function getAutoloaderConfig() { return array( 'Zend\Loader\StandardAutoloader' => array( 'namespaces' => array( __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, ), ), ); } } 

具有完整堆栈跟踪和错误的图像:

关于这个主题已经发布了一个非常相似的问题:Zend Framework 2 tutorial: Module (Application) could not be initialized .

阅读该帖子后,我按照建议的答案建议在 application.config.php 中为 module_paths 设置绝对路径,但这并没有影响我的问题.

application.config.php 摘录:

'module_paths' => array(
        __DIR__.'/../module',
        './vendor',
    ),
<?
namespace Application;

use Zend\Db\TableGateway\Feature;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\ModuleManager\Feature\ServiceProviderInterface;

use Model;
use Zfe;

class Module implements  ServiceProviderInterface { 
public function onBootstrap(MvcEvent $e) {
    $eventManager = $e->getApplication()->getEventManager();
    $moduleRouteListener = new ModuleRouteListener();
    $moduleRouteListener->attach($eventManager);
    $this->initDatabase($e);
}        

public function initDatabase($e) {        
    Feature\GlobalAdapterFeature::setStaticAdapter($e->getApplication()->getServiceManager()->get('Zend\Db\Adapter\Adapter'));
}

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

public function getServiceConfig() {
    return array(
            'factories' => array(
                    'dbadapter'    => new Zfe\Factory('db'),
            ),
    );
}

public function getAutoloaderConfig() {
    return array(
        'Zend\Loader\StandardAutoloader' => array(
            'namespaces' => array(
                __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
            ),
        ),
    );
}
}

任何关于我可以从哪里开始调试的见解都将不胜感激!

根据我的评论,错误表明 ZF 找不到模块 class。在这种情况下,这是因为使用了一个短的开放标签(<? 而不是 <?php)。 PHP 正在输出的代码通常是一个很好的指标。