MyModule.php

The MyModule.php file is the main file where you define things around your Module.

This is an example file:

<?php

namespace Module\BlankModule;

use Controllers\Panel;
use Migration\MigrationHandler;
use Module\Module;

class BlankModule extends Module {

    private $name = "BlankModule";
    private $version = "1.0.0";
    private $author = "Bennet Gallein <me@bennetgallein.de>";

    public function __construct() {
        parent::__construct($this->name, $this->author);
        $this->sidebar();
        $this->sidebarAdmin();
        $this->routes();
        $this->interceptors();
    }

    public function interceptors() {
        $data = [];

        $this->_registerInterceptors($data);
    }

    public function sidebar() {
        $data = [
            ['blank', 'blank']
        ];

        $this->_registerSidebar('blank', 'mdi-database', $data);
    }

    public function sidebarAdmin() {
        $data = [
            [Panel::getLanguage()->get('global', 'm_settings'), 'admin/blank', 2]

        ];

        $this->_registerSidebarAdmin('blank', 'mdi-database', $data);
    }

    public function routes() {

        $data = [
            ['/blank', 'BlankModule\Controllers\PublicController::listAll', [], 'GET'],
        ];
        $api  = [];

        $this->_registerRoutes(array_merge($data, $api));
    }

    /**
     * checks if the module is installed, i.E. checks if the tables are there
     *
     * @return boolean
     */
    public static function checkInstallationStatus() {
        return MigrationHandler::getInstance()->ensureMigrations([
            'create_blank_table'
        ]);
    }

    /**
     * Execute code that installs a module, this might be something 
     * like applying database migrations or moving files 
     * 
     * @return void
     */
    public static function installModule() {
        MigrationHandler::getInstance()->applyMigrations();
    }
}

You can see a lot of helper functions here that are responsible for registering things with the core, like sidebar entries and routes. Mainly 3 important things are registered here in order to add some basic functionality to a module:

_registerSidebar

This function allows you to add an item to the sidebar, visible for customers.

_registerSidebarAdmin

This function allows you to add items to the admin section of the sidebar, with grouping. You can pass an extra parameter to decide what permission level should see this.

_registerRoutes

This adds routes to the routing engine in the core. It is an array of items, each representing a route:

['/blank/:id', 'BlankModule\Controllers\PublicController::listAll', ['id' => '\d+'], 'GET']

As you might have guessed, the first parameter is the route. You can use named parameters, like id in this example. The second parameter is the full namespace path to the Controller that has the function that will be executed when the route is hit (leave out the _Modules part). The third parameter is the array of parameters that are given to the handler-function. if you use a named parameter in the route, you can define a regex that matches. The last parameter is the HTTP-Method that should be used for the route handler, so GET, POST, PUT, PATCH or DELETE.

support

Do you require help?

Wether you have encountered a Bug, ran into a problem setting something up or require generall assistance using some of the features, we want to help you with that.

On our Discord-Server you can ask for help of any kind, suggest new ideas for our products or just hangout and chat!

Open Discord