Reputation: 1753
I'm new to using ZF2, and running into an issue getting the first project I need to work on set up locally. I've gone through and set up the application locally, but when I try to access the home page I receive the following exception error:
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
There is also some output being echoed from a Call Stack trace.. not sure if it will be helpful in resolving this:
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__, ), ), ); } }
An image with the full stack trace and errors:
There was a very similar question already posted about this topic: Zend Framework 2 tutorial: Module (Application) could not be initialized .
Reading through that posting I followed the suggested answers recommendations of setting an absolute path for module_paths within application.config.php
, however this did not affect my problem.
application.config.php
excerpt:
'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__,
),
),
);
}
}
Any insight as to where I could look to start debugging this would be much appreciated!
Upvotes: 1
Views: 1497
Reputation: 33148
As per my comment, the error indicates ZF couldn't find the module class. In this case it is because a short open tag is being used (<?
instead of <?php
). PHP code being output is generally a good indicator of this.
Upvotes: 1