PHP code example of fm-labs / cakephp-settings

1. Go to this page and download the library: Download fm-labs/cakephp-settings library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fm-labs / cakephp-settings example snippets


@TODO

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

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


// 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,
                ],
            ],
        ],
    ],
];



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