Creating a Module

This article describes the process of developing a module in it's purest form. A basic module must contain at least the module information class and should reside within the allocated modules directory. In addition to this, a module should include an updates directory which contains versioning information. To summarise a basic module file structure should look like this:

  • bossblog
    • classes
      • bossblog_module.php
    • updates
      • version.dat

In this example the module name is called bossblog, we will continue with this example.

Module Info Class

The module info class contains details about the module, such as it's name and author. The class is clearly identified by it's class and file name suffix _module. As in the provided file structure, this file is named bossblog_module.php above.

Inside the module info file should be a class declared which extends the Core_Module_Base class. For example:

class BossBlog_Module extends Core_Module_Base { }

At a bare minimum, there must be only one method defined within this class called set_module_info. This method is responsible for returning the details and must return the object Core_Module_Detail which contains these details. So to complete our module, refer to this example:

<?php

class BossBlog_Module extends Core_Module_Base 
{ 
    protected function set_module_info()
    {
        return new Core_Module_Detail(
            "Boss Blog",
            "Adds a blog to your site like a BAWS!",
            "PHP Road",
            "http://phproad.com/"
        );
    }
}

Version Info File

The version info file contains update history for your module. It can be used to keep track of changes made to your module over time. The file is located within the updates folder and is named version.dat.

Inside the version info class should be plain text that references each change, one per line. The first version of your module should contain just one line:

#1 First version

As you improve you module, you can document improvements by simply updating the file. For example:

#1 First version
#2 Added the comments table
#3 Added images to each blog post

This example contains three updates, with three minor version numbers signified by the first part of the line. These updates would be represented as:

  • 1.0.1 - First version
  • 1.0.2 - Added the comments table
  • 1.0.3 - Added images to each blog post

Each version can have a corresponding database script allowing you to modify the database with each version. See the article Managing Table Structure for more details on how to do this.