jkushner jkushner - 1 year ago 180
PHP Question

Module cannot be initialized zf3 already searched internet

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

I have the module added to the modules array inside

Here is my

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(

Here is my

namespace Serve;

class Module
public function getConfig()
return include __DIR__ . '/../config/module.config.php';

I have a bunch of business logic inside my
however nothing that looks to disrupt loading modules.

I cannot seem to find an answer through research. What could be wrong here?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download