Module Basics

PHPR uses a modular approach to development. This means all the features, such as the CMS and Admin functions are provided by different modules. By developing your own module you can perform various tasks, such as:

  • Adding new features to your site
  • Extending exisiting objects, like users or blog posts
  • Extending the Admin Area interface by adding new menu items and forms

Structure of a Module

If you look at a module folder on the file system located under the modules directory, it will contain the following subdirectories:

  • assets
  • classes
  • controllers
  • models
  • updates

The assets directory is an optional directory and will contain files relating to the graphical layer, such as CSS, images and Javascript files needed for your module in the Admin Area. You can create any type of file and folder structure in this directory.

The classses directory should contain library items used by the module. It also must contain a module information declaration class file that ends with the _module suffix, this is used to identify the module. In the purest form, a module only requires a classes and updates folder to work correctly. You can learn more about this by reading the article Creating a Module.

The controllers directory can contain controller and view files which are used for building Admin Area pages specific to the module, such as a Settings page. If you do not plan on adding any new pages to the Admin Area then you do not need to create this directory. For more information on how to customise the Admin Area see the article building_admin_pages.

The models directory is used for storing model classes. Model classes are used for interacting with the database by storing and retreiving information. You can learn more about model classes by reading the article Database Basics.

The updates directory will contain a module’s versioning information, called version.dat, and the SQL scripts required for establishing the database tables needed for the module. This subdirectory is required even if the module does not use the database.

Naming Standard

Module directories and their files must follow a specific naming standard. This allows PHPR to automatically load classes without the need for require() or include() functions.

Module Directory

The top level module folder cannot contain spaces, minus symbols or underscores. The directory must also be all lower case and not begin with a digit. Some examples of incorrect module directory names:

  • BossBlog
  • boss_blog
  • superSHOP
  • 4chan

These are examples of correct module names:

  • bossblog
  • supershop

Class Names

Every class name within a module should start with the module's name followed by an underscore. The file name should also be lower case however, you are allowed to use uppercase lettering in the class names. Some examples of correct class names:

  • BossBlog_ClassName
  • BossBlog_Classname
  • BossBlog_Class_Name

Database Table Names

Database table names follow the same convention as class file names. It should be prefixed with the module name followed by an underscore. When referring to model records you should use the plural representation, for example, blog_posts is preferrable to blog_post.