In this lesson, I propose to consider how the minimum module for Concrete5 CMS is made (in the terminology of the system, modules are called blocks) using the example of the “Separator” module.
I’ll allow myself a small digression and mention that when developing extensions for Concrete5, the
MVC scheme is widely used, for this reason I would recommend to those unfamiliar with it, first decide what it is and only then continue reading.
In the simplest module, we need only 3 files in the blocks / horizintal_line directory:
- controller.php
- view.php
- icon.png
controller.php
By the name it is already clear that this is a controller file. Everyone who is familiar with MVC, I think, understand that without him we can not do. The controller contains the control code of the module, which is responsible for processing all actions performed by the module. Specifically, this controller contains the HorizintalLineBlockController class inherited from the BlockController base class, which performs all the actions we need in this case (installation, output, etc.). Our class contains definitions for the required class fields, such as the module name, description, and caching settings.
<?php defined('C5_EXECUTE') or die("Access Denied."); class HorizintalLineBlockController extends BlockController {
')
Please note that the name of the directory with the module and the name of the controller must match each other because these are the naming conventions. Compliance is determined by:
- take the directory name
- capitalize the first letter and all the first letters after the underscore character, if there is one, like this Horizintal_Line
- remove underscores, we get a HorizintalLine
- at the end, add the class name of the BlockController parent controller and get the HorizintalLineBlockController
If you do not comply with the agreement, the system simply will not find our module and will not be able to install it.
view.php
This file contains PHP and HTML, which are responsible for building the output of the module content on the default page. In our example, the file is extremely simple and contains only two lines.
<?php defined('C5_EXECUTE') or die("Access Denied.");?> <hr />
For any module, you can make an unlimited number of analogues view.php in the templates subdirectory of our module, to change its appearance. These "mappings" can be connected to the module directly through the CMS interface without having to get into the code.
icon.png
The icon of the module, which is entered in the list of modules when it is added to the page.
Note: in all PHP files that are made to work under the control of this CMS, it is necessary to include the following code in the first line:
<?php defined('C5_EXECUTE') or die("Access Denied.");?>
This concludes the first lesson, if the community has an interest, I will continue.
Links for interested
CMS website:
concrete5.orgRussian community:
forum.concrete5russia.ruRussian assembly: the
first and
secondThis module on GitHub:
horizintal_line