Bootstrapping an Add-on (init.php)#
An init.php file must be located at the top level of the add-on directory. It is automatically included by the i-doit system to register the add-on in the core. Developers should use the init.php to make add-on-specific preparations. This includes, among other things, defining constants or registering autoloaders and routes. Callbacks can also be registered here via the "Signal-Slot" component.
Furthermore, report views and dashboard widgets can be registered within the init.php so that i-doit can access them at the appropriate places.
The init.php must contain as little logic as possible so that performance does not suffer. The init.php files of all add-ons are executed on every request!
Checking Whether the Add-on Is Active#
The first code instruction in the init.php must check whether the add-on is active. Only then may additional code be executed!
The required code looks as follows:
1 2 3 4 | |
All additional instructions may only take place within this check!
PSR-4 and Legacy Autoloader#
PSR-4#
For PHP classes created according to PSR-4, i-doit offers a simple way to implement the add-on namespace in the autoloader:
1 2 | |
Legacy Code#
For PHP classes in legacy format (such as authorization system or category classes), the corresponding legacy autoloader must be used. Typically, this is located directly in the add-on directory and should look approximately like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
The legacy autoloader is registered in the init.php as follows:
1 2 3 4 | |
Extending Settings for [tenant-name]#
The displayed settings for [tenant-name] under Administration > [tenant-name] Administration > Settings for [tenant-name] can be extended via an add-on. Further information on this can be found in the article Extending System Settings.