Configuration
Minimal configuration is required to begin using the Module Manager.
php spark module:publish
This publishes the module manager configuration into APPPATH and automatically adds the module-loading script to app/Config/Autoload.php. After that, the system will automatically register each enabled module so that it's available to the framework.
Default Configuration
By default, modules are expected to live in a modules directory at the root of your project, alongside your app and vendor directories. This location is defined in the Module Manager configuration file and can be changed if your project structure requires it.
The configuration file is located at app/Config/ModuleManager.php and contains a single setting that controls where the system looks for modules:
<?php
namespace Config;
use Michalsn\CodeIgniterModuleManager\Config\ModuleManager as BaseModuleManager;
class ModuleManager extends BaseModuleManager
{
public string $folderPath = ROOTPATH . 'modules';
}
Database Setup
The Module Manager uses a database table to track module states and versions. This table is created automatically when you run the Module Manager's migration. Execute the following command to set up the required table:
php spark migrate --all
This creates a modules table that stores information about each module, including its installation status, enabled state, and version information.
Autoloader Cache
The Module Manager maintains a cache file at writable/modules_psr4.php that contains PSR-4 namespace mappings for enabled modules. This file is automatically generated and updated whenever you enable or disable modules.
The autoloader cache is loaded during application bootstrap through CodeIgniter's autoload system. When modules are enabled, their namespaces are added to this cache file. When disabled, they are removed. You should never edit this file manually, as your changes will be overwritten.
Directory Structure
Once configured, your project structure will look something like this:
your-project/
├── app/
├── vendor/
├── public/
├── writable/
│ └── modules_psr4.php (Generated automatically)
└── modules/ (Your modules directory)
├── blog/
├── shop/
└── forum/
Each module directory contains its own complete module structure with source files, migrations, and configuration.