Skip to Content search facebook instagram pinterest twitter youtube

Developing modules

Development of third-party modules is the backbone of all custom development within SproutCMS.

Typical dev process

A high-level overview of a typical development process would be: 

  1. Use the module builder located within the dev tools to create a skeleton module
  2. Register the module in config/config.php
  3. Run a database sync to get the new tables
  4. Polish the admin area - change field types, set up dropdowns, validation, etc
  5. Develop front-end controllers and views

Module registration

Modules are registered by adding the name of the module in the config/config.php file

config/config.php

/**
 * Enabled sprout v3 modules
 */
Sprout\Helpers\Register::modules([
	'HomePage',
	'Blogs',      // new module in "modules/Blogs" directory
]);

Namespaces

All modules must have a unique namespace. The namespace must follow the following format:

SproutModules\<Organisation>\<ModuleName>

The final segment of the namespace - the name of the module - is also used as the name of the directory in the modules directory.

Therefore, a blog module produced by the company Acme Inc would use the namespace SproutModules\AcmeInc\Blogs and the files would be located in the directory modules/Blogs.

All code within this module would existin within sub-namespaces within this namespace, and the file/directory structure mirrors the namespace layout.

Futher to the above example, a controller in the blogs module would be in the namespace SproutModules\AcmeInc\Blogs\Controllers and the file would go in the directory modules/Blogs/Controllers.