R
R
Ruslan2015-05-13 12:42:40
MySQL
Ruslan, 2015-05-13 12:42:40

Where to store parameters of components of several projects in one?

There is one project code, it will be used by several owners (there will be a separate database with a list of such owners) each project owner has its own component settings (domain, sms accounts, queue manager, payment system, database, logos, etc.), you need decide where to store these settings:
1. In the database of "owners" + caching
2. In files, and connect them dynamically by ID
The complexity adds that there will be versions of projects for local, preprod and prod
While there are about 50 fields of unique settings
per day while there are about 4000 users, with each new owner the figure will certainly increase.
Who faced what reefs can be in various options?
Maybe there is another option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
restyler, 2015-05-13
@restyler

if there are more than a dozen owners, then I recommend creating a setting table with the name / type / value / owner_id fields and dynamically initialize the components using these values ​​​​from the database. There is another option if indexing, well-read migrations and complex selections by settings are not needed - just in the owner table a blob settings field is made where all values ​​are serialized + type binding is done in the model:

class Owner { 
public function getSettingsConfig() {
        return [
            'setting1',
            'setting2',
            'setting3',
        ];
    }

    public function getSettingValue($var, $default = null)
    {
       $settings = unserialize($this->settings); // @TODO: add caching for effective multiple calls
       return isset($settings[$var]) ? $settings[$var] : $default; 
    }

    public function getSettingsValues()
    {
        $settings = unserialize($this->settings); // @TODO: add caching for effective multiple calls
        $settingsConfig = $this->getSettingsConfig();
        foreach ($settingsConfig as $settingName) {
            if (empty($settings[$settingName])) {
                $settings[$settingName] = '';
            }
        }
        return $settings;
    }
}

in the view of the settings page we do:
$settings = $model->getSettingsValues();

<?= Html::textInput('settings[setting1]', $settings['setting1'], ['class' => 'form-control']) ?>
<?= Html::dropdownList('settings[setting2]', $settings['setting2'], ['class' => 'form-control']) ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question