Creating a Module
You're asked to create a new module for managing company's location information. We will call this module the Locations
module.
Step 1: Location of your module
There are two potential locations for your project. The sa
module directory, and your application's module directory.
The general rule of thumb for identifying the home for your module is,
Application specific modules go in a custom app modules directory
Core SiteAdmin modules go in the
sa
modules directory.
Don't see a directory for custom modules?
If you're working with a fresh installation of SiteAdmin, you'll probably only see a sa
directory in {project_root}/sitadmin/modules
. For application specific modules, create a new directory. The directory name will be used for PSR-4 class autoloading, so it must be namespace friendly.
By convention, the application modules directory is named after your project, capital-cased. For example, if your project is called "Awesome Fishing Supplies", you might name the directory "AwesomeFishingSupplies." After naming your custom module directory, your directory structure should look like this:
Step 2: Module Directory Structure
Classes
The classes
directory will contain all of your PHP classes. This will include controllers, repositories, configuration, and helpers.
Classes/Models
The models
directory will contain all of your doctrine entities.
CSS
The css
directory will contain all CSS stylesheets.
JS
The js
directory will contain all JS scripts.
Views
The views
directory will contain all templates for views and subviews.
Step 3: Create Module Configuration File
All modules contain a configuration file. This file is located in the {module_root}/classes
directory, and must match the case sensitive name of the module. For example, the configuration file for our Locations
module configuration file will reside in {module_root}/classes/LocationsConfig.php
.
Step 4: Filling out the module's configuration
init()
The init()
method contains code that is executed before the module is fully initialized. This is where you would place modRequests, event listeners, or code that other parts of the module expect to be available.
getRoutes()
The getRoutes()
method returns an array of the module's application and administrative routes. View the routing documentation for more details.
getNavigation()
The getNavigation()
method specifies all the module's administrative navigation links. These links will appear in the admin dashboard's main menu.
Parameter | Description |
| A unique ID for the nav item. Name should be structured as |
| The navigation item's label. |
| The route that the nav item is linked to. |
| The |
getSettings()
The module's settings should be defined in the getSettings()
method. This includes API keys, pagination options, test mode toggles, etc.
Parameter | Description |
| The name of the module associated with this setting. This name should be human readable (i.e instead of |
| The setting's default value. Data type varies depending on the setting's |
| The type of field. |
Last updated