phemellc / yii2-settings

Yii2 Settings Module
Other
151 stars 74 forks source link

How to seed settings #53

Closed philippfrenzel closed 7 years ago

philippfrenzel commented 8 years ago

Hi can you write a short doku about how to seed settings?!

Thanks Philipp

schmunk42 commented 8 years ago

Related ;) https://github.com/phemellc/yii2-settings/issues/37

schmunk42 commented 8 years ago

What's about migrations to seed settings, any objections?

arisk commented 8 years ago

Migrations are probably the best idea.

philippfrenzel commented 8 years ago

Hi, currently solved it like:


use yii\db\Migration;

class m160605_131238_holiday_country_params extends Migration
{
    public function up()
    {
        $settings = Yii::$app->settings;
        //the number of holidays in Austria
        $settings->set('newAT', '25', 'holiday', 'integer');
        //the number of holidays in Germany
        $settings->set('newDE', '28', 'holiday', 'integer');
        //the number of holidays in Swiss
        $settings->set('newCH', '25', 'holiday', 'integer');

        //the mail adress of the administrator
        $settings->set('hrDepartment', 'hr@frenzel.net', 'holiday', 'string');

        //when does the fiscal year start
        $settings->set('fiscalYear', '-05-01', 'holiday', 'string');
    }

    public function down()
    {
        echo "m160605_131238_holiday_country_params cannot be reverted.\n";

        return false;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
schmunk42 commented 8 years ago

This should be added to the docs, IMHO.

schmunk42 commented 7 years ago

Can be closed with the above commit.