GithubHelp home page GithubHelp logo

cakephp-settings's Introduction

Settings plugin for CakePHP

Build Status Coverage Status Gitter

The Settings Plugin allows you to manage your settings (normally used with cake's Configure-class) in your database.

Note: The Settings-plugin is prefix-minded. An example: Prefix.Name.

Installation

You can install this plugin into your CakePHP application using composer. For existing applications you can add the following to your composer.json file:

"require": {
	"cakemanager/cakephp-settings": "dev-master"
}

And run /composer update.

Configuration

You will need to add the following line to your application's bootstrap.php file:

Plugin::load('Settings', ['bootstrap' => true, 'routes' => true]);

// or run in your shell

$ bin/cake plugin load -b -r Settings

Next you need to create the table. Use the following command to initialize the settings-table.

$ bin/cake migrations migrate -p Settings

Usage

The Setting-class works the same like the Configure-class from CakePHP itself.

You can include the class with:

use Settings\Core\Setting;

Write

You can write settings with the following:

Setting::write('App.Name', 'Custom Name');

The value Custom Name is now written to the database with the key App.Name. The empty array can contain multiple options

Read

Now we gonna read the value from our just created key. Use:

Setting::read('App.Name');

This will return our value: Custom Name.

Register

To prevent missing configurations when migrating to another environment the register method is introduced. Use the following to make sure the configuration exists in your application:

Setting::register('App.Name', 'Default Value', []);

Options

The following options are available:

  • description - Description of your setting.
  • type - Type to use like text, select, and more.
  • options - Array with available options. In combination with the type = select option, this will generate a select-box with the given options.
  • editable - Bool if the setting should be editable.
  • weight - Weight (order) of the setting.

The options key can handle multiple types. You can define an array with options, but you can also create a close to prevent long queries on every request. Example:

Setting::register('App.Index', false, [
    'options' => function() {
        return TableRegistry::get('Blogs')->find('list')->toArray();
    }
]);

Using the setting-forms

If you are using the CakeAdmin Plugin, we will create a default form where you can edit your settings (if the field editable isset to 1). The Settings-Plugin will automatically add a menu-item to the admin-area.

If you click the menu-item you will see a list with all editable settings who contains the chosen prefix (or default: App).

Register

To add your prefix to the settings-list use the following:

Configure::write('Settings.Prefixes.Test', 'Test');

cakephp-settings's People

Contributors

bobmulder avatar casmo avatar jpkleemans avatar leoruhland avatar lorenzo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cakephp-settings's Issues

Not found cakephp-settings

I'm having trouble with the installation of dependence by the composer.
The mistake is giving not find the cakephp-settings directory.

And I checked the cakephp-plugins.php file and it is with this line:

'Settings' => $baseDir . '/vendor/cakemanager/cakephp-settings/'

And cakemanager checked the folder and is the plugin with the Settings name.

Solution would be in cakephp-plugins.php file:

'Settings' => $baseDir . '/vendor/cakemanager/Settings/'

Extend settings views

Is it possibile to extend or costumize just like users, roles, and post types in admin area, the Settings index and prefix.ctp?

Postgres issue

Hey guys. Not everyone likes/uses mysql. So, being one of the few, I found this error:

[PDOException]
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "("
LINE 1: ...YING (50) NOT NULL DEFAULT '', "editable" BOOLEAN (1) NOT NU...

When trying to run migrate on a postgres database.

getting rid of the (1) should do the trick. Isn't needed on mysql either.

In the file 20150126111319_settings_initial.php there are two boolean fields.

I removed the 'limit' setting (limit => 1) on both fields and then I was able to run the migration.

Installation problem

I might be being daft, but both methods of installation aren't working.

Trying composer require cakemanager/cakephp-settings (as seen on packagist) fails with "Your requirements could not be resolved to an installable set of packages." error, and I get the same if I add the appropriate line into my composer.json directly, then composer update.

Any ideas what's up?

3.6 Deprecation warnings

Connection::schemaCollection() is deprecated. Use Connection::setSchemaCollection()/getSchemaCollection() instead. - E:\Development\WampServer-64-3.0\www\PWA-Kassa\backbone\vendor\cakemanager\cakephp-settings\src\Core\Setting.php, line: 344

Seems to me an update could be handy.

Migration: value & description can't have a default value

[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1101 BLOB, TEXT, GEOMETRY or JSON column 'value' can't have a default value
SQLSTATE[42000]: Syntax error or access violation: 1101 BLOB, TEXT, GEOMETRY or JSON column 'description' can't have a default value

My environment: Mysql 5.7 on OSX Capitan
Because columns 'value' and 'description' is "text", that's why they can't have default value

settings editable by roles

hi

thanks a lot for your work on cake plugins

would be nice to extend this to be able to use with your users plugin so some settings can be edited only by some roles

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.