Basic Module Structure

Module folder structure

  • controllers/
  • models/
  • views/
  • Module.php (more information below)
  • config.php (more information below)
  • module.json (more information below)

Base Module Class



If the module is placed inside the /protected/modules folder, you can create a config.php in the module directory which provides automatic loading without manually modifing the application config.

The config.php should return an array including following fields:

Example of a config.php file:


use johndoe\example\Module;
use humhub\widgets\TopMenu;

return [
    'id' => 'example',
    'class' => 'johndoe\example\Module',
    'namespace' => 'johndoe\example',
    'events' => [
        array('class' => TopMenu::className(), 'event' => TopMenu::EVENT_INIT, 'callback' => array('johndoe\example\Module', 'onTopMenuInit')),

Note: Do not execute any code in the config.php - the result will be cached!


This file holds basic information about the module like name, description or current version. Locate this file in the root directory of the module.

    "id": "example",
    "name": "My Example Module",
    "description": "My testing module.",
    "keywords": ["my", "cool", "module"],
    "version": "1.0",
    "humhub": {
    "minVersion": "0.20"