andrylik/yii2-settings

Settings Manager for Yii2 with the possibility of translating values.

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

0.2.0 2023-12-24 15:34 UTC

This package is auto-updated.

Last update: 2024-04-24 16:19:01 UTC


README

68747470733a2f2f796969736f66742e6769746875622e696f2f646f63732f696d616765732f7969695f6c6f676f2e737667

Yii2 Settings Extension


Settings Manager for Yii2 with the possibility of translating values.

Installation

Via Composer.

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

Database Migrations

Before usage this extension, we'll also need to prepare the database.

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

Configuration

Module Setup

Configure "Yii2 Settings Extension" module in backend/config/main.php:

'modules' => [
    'settings' => [
        'class' => 'andrylik\settings\Module',
    ],
],

If you need to translate the values to other languages

add parameters in common/config/params.php

return [
    // ...
    'languages' => ['uk', 'ru', 'en'], //languages to translate
    'defaultLanguage' => 'uk' //default app language
];

Also specify the language of the application common/config/main.php

return [
    // ...
    'language' => 'uk',
    //..
];

Component Setup

Configure Settings Component common/config/main.php

'components' => [
    'cache' => [
        'class' => \yii\caching\FileCache::class,
        'cachePath' => '@frontend/runtime/cache'
    ],
    'settings' => [
        'class' => 'andrylik\settings\components\Settings',
    ],
],

Usage:

Go to http://backend.yourdomain.com/settings for managing your settings

Use the settings in your application

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

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