Application Modules

An application module is a component with a defined structure that implements the functionality of a module's templates.

All application modules are based on (inherit) the Module component and are located in the /modules directory.

Some application modules also have a partial base implementation in equivalent core modules located in the /bff/modules directory.

The controller is divided into three components:

  • Base: the base controller. It contains the general logic of the module controller: initializing components, constants, and mandatory methods described below.
  • Frontend: the frontend controller. The methods handle page rendering and form processing on the frontend.
  • Admin: the admin controller. The methods handle the module's logic in the admin panel: lists, forms, settings.

The Base controller inherits from Module, except in cases where an equivalent module exists in the core.

Frontend and Admin controllers have the same class name, and module functionality is only available in either the frontend or the admin panel context.

The module also implements work with the database. All SQL queries should be executed through the methods declared in the module model, based on the Model class.

General Module File Structure

  • tpl/def/* - module templates: admin.* - templates for the admin panel, the rest - for the frontend
  • install.sql - table structure required for the module
  • module.adm.class.php - admin controller
  • module.bl.class.php - base controller
  • module.class.php - frontend controller
  • module.model.php - model
  • m.module.class.php - module menu for the admin panel

There is also an alternative version of file naming:

  • admin.php - admin controller
  • base.php - base controller
  • frontend.php - frontend controller
  • model.php - model
  • menu.php - module menu for the admin panel

You can create the basic structure of a module in debug mode in the admin panel section "Development / Create Module".

Module Class Module

The base class that implements:

  • all the necessary methods for working with module templates
  • initialization of module components and calling methods of attached components
  • shortcut methods for working with errors
  • generating links in the admin panel and on the frontend
  • working with site settings within the module
  • some SEO methods
  • shortcut methods for accessing some core modules: users, bills, svc, seo

Base Module Components

All base module components are accessible through $this->:

errors - working with errors

security - working with sessions

db - working with database

input - working with incoming request parameters from GET, POST, and others

locale - working with localization and localized data

Base Controller (Base)

The base controller must declare the following methods:

public function init() - module initialization. Additional components required for this module can be added to the autoload map here.

public static i() - shortcut method to access the object of this module

/**
 * Shortcut
 * @return [Module]
 */
public static function i()
{
    return bff::module('[module]');
}

public static model() - shortcut method to access the model object of this module

/**
 * Shortcut
 * @return [Module]Model
 */
public static function model()
{
    return bff::model('[module]');
}

public sendmailTemplates() - declaration of the list of email templates used in this module

public seoTemplates() - declaration of the list of SEO pages used in this module

public static url() - method to generate URLs for pages created by this module

The base controller also declares constants and methods to initialize the components included in this module.

Module Initialization

Loading of the module is done using autoload. The initialization of the module object depends on the admin/frontend context. The management of module objects and their immediate initialization is done in the application class bff. There are several ways to initialize the application module (obtain the module object). Let's consider the example of the Users module:

Users::i() - access the module controller using a shortcut method (preferred)

bff::module('users') - access the module controller using the application class

Examples of calling module methods:

Users::i()->testData() - calling an object method

Users::testData() - calling a static method

Users::model() - accessing the model object

Thus, access to the module object is always done through the keyword that matches the name of the frontend or admin controller of the module class. When initializing the module, the init() method of the module will be called first.