Developers

Framework

Commentics uses a custom-made MVC (Model-View-Controller) framework.

This means that the code is split into 3 parts:

Controller

The controller orchestrates everything. It gets any user-submitted data, uses a model (or more) to do all the work and finally decides which view to display. It understands the why. Controllers should be as small as possible. Typically each page has its own controller meaning controllers aren't re-usable.

Model

The model is loaded by the controller. It does all the hard work like reading from and saving to the database, sending emails and writing to files. Models don't understand the why but they do know the how. A good model is a re-usable one (allowing other controllers to use it). One controller might load many models.

View

The view is loaded by the controller. Its purpose is to display the HTML. The view shouldn't have any "logic" code inside. The logic is separated and should be "passed down" by the controller. A good view should allow a frontend developer to work on it without having to know any backend code.

In Commentics we can see that in the 'backend', 'frontend' and 'install' folders, the code is split up into the above MVC pattern.

Elsewhere

We also have the /system/library/ files. These make it easier for the controllers and models by providing the code they need to do very rudimentary things like querying the database, encrypting data and accessing the session.

Other places worth mentioning:

  • /3rdparty/ These are the external scripts used by the application
  • /system/backups/ This is where the 'Tool -> Database Backup' feature stores its backups
  • /system/cache/ This is where the template engine puts its parsed templates
  • /system/database/ These are the different database drivers e.g. MySQL, MSSQL, PostgreSQL
  • /system/engine/ These are the core classes that the controllers and models extend from
  • /system/helper/ This is code that assists the application but doesn't fit anywhere
  • /system/logs/ This is where the log files are stored such as the error log
  • /system/modification/ This is where the virtually modified files are stored
  • /system/startup.php This file includes all of the other files
  • /uploads/ This is where user-uploaded images are kept
Routing

To route to the method of a controller, simply use something like:

index.php?route=main/dashboard/dismiss

In the above URL, 'main' is the folder, 'dashboard' is the file and 'dismiss' is the method.

By omitting the method, the index() method will be called. Note that magic methods such as __construct() are blocked. Make sure the method is public.