ZF2 Modules

ZF Modules

  1. The minimal requirement for a module is to have a file named Module.php.
  2. In it we specify the module configuration and the location of the classes belonging to this module to be autoloaded.
  3. The methods in the < ModuleName >\Module class responsible for the configuration and autoloading are called getConfig and getAutoloaderConfig respectively.

/module/Application (by default)
Advantages:

  1. Application Grouping
  2. Middleware
  3. Re-use
  4. Code compartmenalisation
  1. bootstrap loads Zend/ModuleManager
  2. loads module/Application
  3. loads module/*

BookList Module Structure

zf2_module_dir_structure.PNG
.
|____autoload_classmap.php
|____config
| |____module.config.php
|____Module.php
|____src
| |____BookList
| | |____Controller
| | |____Form
| | |____Model
|____view
| |____book-list
| | |____book

Module Directory Files and Functions

File/Directory Location Purpose
Module.php module loads when module is called
zf2_module_functions.PNG

Plugging in a Module

ZF2 reads module information from the ./config/application.config.php

'modules' => array(
        'Application',
        'BookList',    // **HAS TO BE ADDED MANUALLY**
    ),
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License