2017 © Pedro Peláez
 

yii2-extension yii2-settings

Yii2 Settings Module

image

h0rseduck/yii2-settings

Yii2 Settings Module

  • Wednesday, May 16, 2018
  • by h0rseduck
  • Repository
  • 1 Watchers
  • 1 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 21 Forks
  • 0 Open issues
  • 24 Versions
  • 20 % Grown

The README.md

Yii2 Settings

Simple Yii2 settings extension, (*1)

Latest Stable Version Total Downloads License Build Status, (*2)

Installation

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

php composer.phar require --prefer-dist h0rseduck/yii2-settings "*"

or add, (*5)

"h0rseduck/yii2-settings": "*"

to the require section of your composer.json., (*6)

Configuration

Database Migrations, (*7)

Before usage this extension, we'll also need to prepare the database., (*8)

php yii migrate --migrationPath=@vendor/h0rseduck/yii2-settings/migrations

Module Setup, (*9)

To access the module, you need to configure the modules array in your application configuration:, (*10)

'admin' => [
    'modules' => [
        'settings' => [
            'class' => 'h0rseduck\settings\Module',
            // Also you can override some controller properties in following way:
            'controllerMap' => [
                'default' => [
                    'class' => 'h0rseduck\settings\controllers\DefaultController',
                    'searchClass' => [
                        'class' => 'h0rseduck\settings\models\search\SettingSearch',
                        'pageSize' => 25
                    ],
                    'modelClass' => 'Your own model class',
                    'indexView' => 'custom path to index view file',
                    'createView' => 'custom path to create view file',
                    'updateView' => 'custom path to update view file',
                ]
            ]
        ],
    ],
]

You can then access settings page by the following URL: http://localhost/path/to/index.php?r=admin/settings/, (*11)

Component Setup, (*12)

To use the Setting Component, you need to configure the components array in your application configuration:, (*13)

'components' => [
    'settings' => [
        'class' => 'h0rseduck\settings\components\Settings',
    ],
]

Usage:

$settings = Yii::$app->settings;

$value = $settings->get('section', 'key');

$settings->set('section', 'key', 125.5);

$settings->set('section', 'key', 'false', SettingType::BOOLEAN_TYPE);

// Checking existence of setting
$settings->has('section', 'key');

// Activates a setting
$settings->activate('section', 'key');

// Deactivates a setting
$settings->deactivate('section', 'key');

// Removes a setting
$settings->remove('section', 'key');

// Removes all settings
$settings->removeAll();

$settings->invalidateCache(); // automatically called on set(), remove();  

Manage custom settings

You can use your own form model to manage custom settings for your web application via SettingsAction. To use the SettingsAction class you need to follow the following steps:, (*14)

1) Create your own model, for example:, (*15)

 Yii::t('app', 'Application Name'),
            'adminEmail' => Yii::t('app', 'Admin Email'),
        ];
    }
}
```

2) Create view file, named `settings.php` with the following content:

```php
title = Yii::t('app', 'Manage Application Settings');
?>


field($model, 'appName'); ?>

field($model, 'adminEmail'); ?>

 'btn btn-success']) ?>



3) Add settings action to your controller class as follows:, (*16)

<?php

namespace app\controllers;

use yii\web\Controller;

/**
 * Class SiteController
 *
 * @package app\controllers
 */
class SiteController extends Controller
{
    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'manage-settings' => [
                'class' => \h0rseduck\settings\actions\SettingsAction::class,
                // also you can use events as follows:
                'on beforeSave' => function ($event) {
                    // your custom code
                },
                'on afterSave' => function ($event) {
                    // your custom code
                },
                'modelClass' => \app\models\forms\ConfigurationForm::class,
            ],
        ];
    }
}

Now you can access to the settings page by the following URL: http://localhost/path/to/index.php?r=site/manage-settings/, (*17)

Internationalization

All text and messages introduced in this extension are translatable under category 'h0rseduck.settings'. You may use translations provided within this extension, using following application configuration:, (*18)

return [
    'components' => [
        'i18n' => [
            'translations' => [
                'h0rseduck.settings' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@h0rseduck/settings/messages',
                ],
                // ...
            ],
        ],
        // ...
    ],
    // ...
];

The Versions

16/05 2018

dev-master

9999999-dev

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy
by Avatar h0rseduck

settings config yii2 storage

16/05 2018

2.2.3

2.2.3.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy
by Avatar h0rseduck

settings config yii2 storage

16/05 2018

2.2.2

2.2.2.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy
by Avatar h0rseduck

settings config yii2 storage

13/04 2017

2.2.1

2.2.1.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

settings config yii2 storage

23/03 2017

2.2

2.2.0.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

settings config yii2 storage

18/02 2017

2.1

2.1.0.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

settings config yii2 storage

16/02 2017

2.0

2.0.0.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

settings config yii2 storage

12/12 2016

1.10.3

1.10.3.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

settings config yii2 storage

22/11 2016

1.10.2

1.10.2.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

settings config yii2 storage

11/11 2016

1.10.1

1.10.1.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

settings config yii2 storage

10/11 2016

1.10

1.10.0.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

settings config yii2 storage

10/11 2016

1.9

1.9.0.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

settings config yii2 storage

09/11 2016

1.8.1

1.8.1.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

settings config yii2 storage

09/11 2016

1.8

1.8.0.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

settings config yii2 storage

01/11 2016

1.7

1.7.0.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

settings config yii2 storage

03/08 2016

1.6

1.6.0.0

Yii2 Settings Module

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

settings config yii2 storage

25/07 2016

1.5

1.5.0.0

Simple Yii2 settings extension

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

settings config yii2 storage

20/07 2016

1.4

1.4.0.0

Simple Yii2 settings extension

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

14/07 2016

1.3

1.3.0.0

Simple Yii2 settings extension

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

14/07 2016

1.2

1.2.0.0

Simple Yii2 settings extension

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

05/07 2016

1.1

1.1.0.0

Simple Yii2 settings extension

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

06/01 2016

1.0.2

1.0.2.0

Simple Yii2 settings extension

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

08/10 2015

1.0.1

1.0.1.0

Simple Yii2 settings extension

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

17/06 2015

1.0

1.0.0.0

Simple Yii2 settings extension

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2