In basic terms, Includable modules are simple PHP applications. They follow a standard structure and use provided classes and methods to exchange data and show information to users.
A common directory structure for Includable modules looks a little like this:
calendar/ ├── module.json ├── api/ | ├── schedule.php | └── tasks.php ├── web/ | ├── index.php | └── static/ | ├── scripts.js | └── styles.css ├── manager/ | └── user-tasks.php └── hooks/ └── course-tab-tasks.php
This file contains all the information about the module that Includable needs to be able to show it in the Marketplace and execute it. It is a JSON file, more information about its contents can be found here.
Directories for the different types of controllers
Controllers are how Includable decides which content to show in which situation. They also allow us to easily let modules hook into other modules. Basically, a Controller has a name and contains the path to a PHP file that is executed when that specific controller is called. Controllers are defined in themodule.json file and can be separated into roughly four categories:
- Web: the most standard controller, called when a user visits the module directly on the web or on mobile.
- API: the controller that handles any API and AJAX request to the module.
- Manager: there are multiple hooks to add pages to the Includable Community Manager.
- Hooks: any controllers that are called by other modules.
Best practice is to put PHP files for each of these controller types into their own directory, to keep structure as the number of controllers in your module grow.