Coder Social home page Coder Social logo

cakephp-settings's Introduction

Settings plugin for CakePHP

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.'
        ]);
    }

cakephp-settings's People

Contributors

fm-labs avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.