Module Class

The Module class allows you to easily load, unload, check if a module exists or if it is loaded, or get a list of all modules loaded.

load($module, $path = null)

The load method allows you to load one or more modules at runtime. If the module cannot be found a ModuleNotFoundException will be thrown.

Static Yes
Parameters
Param Default Description
$module required Name of the module to be loaded, or an array of modules.
$path null Path to the given module. You can use this to load modules from outside the defined module paths.
Returns void
Example
// load a users module
Module::load('users');

// load the users module from a specific directory
Module::load('users', '/path/to/modules/users/');

// load multiple modules from a single module installation
Module::load( array('Users' => '/path/to/modules/users/', 'Groups' => '/path/to/modules/groups/') );

// load the non-existent module
Module::load('awesome'); // Throws a ModuleNotFoundException

You can configure whether or not the modules routes should be loaded as well, through the config key "routing.module_routes".

unload($module)

The unload method allows you to unload a module at runtime.

Static Yes
Parameters
Param Default Description
$module required Name of the module to be unloaded.
Returns void
Example
// unload the users module
Module::unload('users');

This will (attempt to) remove all routes that where defined by the module (in its routes.php file) when it was loaded!

loaded($module = null)

The loaded method allows you to check if a module is currently loaded. If no module name is given then all loaded module are returned.

Static Yes
Parameters
Param Default Description
$module null Name of the module to be checked.
Returns bool|array
Example
// Check if the users module is loaded
$loaded = Module::loaded('users');

// Get all loaded modules
$loaded = Module::loaded();
/*
Returns something like:
array(
    'users' => '/path/to/users',
    'groups' => '/path/to/groups',
)
*/

exists($module)

The exists method allows you to check if a module exists, i.e. if it can be found in one of the configured module paths. If found, it returns the path to the module. If not, it returns false.

Static Yes
Parameters
Param Default Description
$module null Name of the module to be checked.
Returns bool|string
Example
// Optionally load the comments module
if (Module::exists('comments'))
{
	Module::load('comments');
}