Page tree

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Code Block
 * @var \App\View\AppView $this
 * @var string $message

<div class="row">
    <div class="col-xl-12">
        <div id="panel-1" class="panel">
            <div class="panel-hdr">
                    <?php echo __('Example Module'); ?>
                    <span class="fw-300"><i><?php echo __('Hello World'); ?></i></span>
            <div class="panel-container show">
                <div class="panel-content">

                    <!-- Output "Hello World (HTML)" that was set by the controller -->
                    <?= h($message); ?>

                    <table class="table table-striped m-0 table-bordered table-hover table-sm">
                            <th><?= __('Host name') ?></th>
                            <th><?= __('Note') ?></th>

                        <!-- Repeat this TR for each record in $scope.notes -->
                        <tr ng-repeat="note in notes">
                                <!-- Print the content of the variable -->
                                {{ }}
                            <td>{{ note.notes }}</td>




Use a own database

If you need to store data which has no relation to openITCOCKPIT data itself, it is recommended to store these records to an own database. Modules can create and manage own database connections.

Define a new Database Connection

Create the file /ExampleModule/config/datasource.php

Code Block
$mcp = new \App\itnovum\openITCOCKPIT\Database\MysqlConfigFileParser();
$ini_file = $mcp->parse_mysql_cnf('/opt/openitc/etc/mysql/mysql.cnf');

return [
    'Datasources' => [
        'plugin_connection' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => true,
            'host' => $ini_file['host'],
            'username' => $ini_file['user'],
            'password' => $ini_file['password'],
            'database' => 'plugin_database',
              * You do not need to set this flag to use full utf-8 encoding (internal default since CakePHP 3.6).
            'encoding' => 'utf8mb4',
            'timezone' => 'UTC',
            'flags' => [],
            'cacheMetadata' => true,
            'log' => false,

             * Set identifier quoting to true if you are using reserved words or
             * special characters in your table or column names. Enabling this
             * setting will result in queries built using the Query Builder having
             * identifiers quoted when creating SQL. It should be noted that this
             * decreases performance because each query needs to be traversed and
             * manipulated before being executed.
            'quoteIdentifiers' => true,

This example uses the username, password and host configuration of the openITCOCKPIT mysql.cnf. You can also hardcode own username and password credentials.

Load and use own database configuration

Open the file /ExampleModule/src/Plugin.php and load the new database configuration inside of the bootstrap Method. You can copy and past this code.

Code Block
class Plugin extends BasePlugin {
    public function bootstrap(PluginApplicationInterface $app): void {
        $datasources = Configure::consume('Datasources');

        //Check if configuration is already loaded to avoid:
        // => Cannot reconfigure existing key "plugin_test"
        if(ConnectionManager::getConfig(key($datasources)) === null) {

In the last step you need to set the database configuration in all Table classes, that should use your own database connection.

Code Block
class ExampleNotesTable extends Table {
    public static function defaultConnectionName(): string {
        //debug(Configure::read('Datasources.plugin_test')); // Returns the config
        return 'plugin_connection';

Notice: The method defaultConnectionName has to be static!


Linking core tables with plugin tables