A free and open-source book on Zend Framework for beginners


3.9. Module Entry Point

In ZF3, your web application consists of modules. By default, you have the single Application module, but can create more if needed. Typically, your own modules are stored in APP_DIR/module directory, while third-party modules live in APP_DIR/vendor directory.

On start up, when the Zend\Mvc\Application object is created, it uses the Zend\ModuleManager component to find and load all modules registered in application config.

Each module of the web application has the Module.php file which is some kind of entry point for the module. This file provides the Module class. Below, the contents of skeleton application's Module class is presented:

<?php 
namespace Application;

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

The class Module belongs to the module's namespace (for the main module it belongs to the Application namespace).

The getConfig() method is typically used to provide module's configuration to Zend Framework (module.config.php file).

You can also register some event listeners here, we'll see how to do this later in Creating a New Module chapter.


Top