fm-labs/cakephp-settings

There is no license information available for the latest version (1.1.1) of this package.

Settings plugin for CakePHP

Installs: 78

Dependents: 2

Suggesters: 3

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:cakephp-plugin

1.1.1 2023-03-25 15:25 UTC

This package is auto-updated.

Last update: 2024-03-25 18:05:22 UTC


README

Store configuration settings in database.

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

$ composer require fm-labs/cakephp-settings

Run migrations

$ ./bin/cake migrations migrate --plugin Settings

Usage

Manage settings via Console

// Initialize settings from schema
$ ./bin/cake settings init

// List available settings
$ ./bin/cake settings list

// List configured settings values
$ ./bin/cake settings values

// Get setting value
$ ./bin/cake settings get-value

// Update setting value
$ ./bin/cake settings set-value

Manage settings programmatically

@TODO

Load settings

To load settings for your app:

// In your bootstrap.php or in Plugin::bootstrap()
\Cake\Core\Configure::load('app', 'settings');

To load plugin settings:

// In your bootstrap.php or in Plugin::bootstrap()
\Cake\Core\Configure::load('PluginName', 'settings');

Settings Schema file

App and plugin settings are defined in settings schema file, which should be in your app's or plugins's config directory. APP/config/settings.php or PLUGINS/MyPlugin/config/settings.php respectively.

<?php
// Example settings.php for User plugin
return [
    'Settings' => [
        'User' => [
            'groups' => [
                'User.Auth' => ['label' => __('User Authentication')],
                'User.Signup' => ['label' => __('User Signup')],
            ],
            'schema' => [
                'User.Login.disabled' => [
                    'group' => 'User.Auth',
                    'type' => 'boolean',
                    'default' => true,
                ],
                'User.Signup.disabled' => [
                    'group' => 'User.Signup',
                    'type' => 'boolean',
                    'default' => true,
                ],
                'User.Signup.verifyEmail' => [
                    'group' => 'User.Signup',
                    'type' => 'boolean',
                    'default' => false,
                ],
            ],
        ],
    ],
];

Events

The Settings.build event will be triggered, when the global settings schema gets initialized.

    /**
     *
     */
    public function implementedEvents()
    {
        return [
            'Settings.build' => 'buildSettings',
        ];       
    }

    /**
     * @param \Cake\Event\Event $event The event object
     * @param \Settings\Settings $settings The settings object
     * @return void
     */
    public function buildSettings(Event $event, $settings)
    {
        // load a settings schema config file
        //$settings->load('User.settings');
        // add a setting group
        $settings->addGroup('User.Password', [
            'label' => 'User Password Settings'
        ]);
        // add a setting
        $settings->add('User.Password.expireInDays', [
            'group' => 'User.Password',
            'type' => 'int',
            'label' => 'Password expiry (in days)',
            'help' => 'The password will expire in X days and a new password needs to be entered by the user at the next login.'
        ]);
    }