PHP code example of germanow / yii2-active-record-seeder

1. Go to this page and download the library: Download germanow/yii2-active-record-seeder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

germanow / yii2-active-record-seeder example snippets


use germanow\yii2ActiveRecordSeeder\ActiveRecordSeeder;
use germanow\yii2ActiveRecordSeeder\AddFiller;
use germanow\yii2ActiveRecordSeeder\OverwriteFiller;

$seeder = new ActiveRecordSeeder([
    'fillers' => [
        // Default filler is EmptyFiller, which fill table if it's empty
        [
            // Specify name of ActiveRecord model class
            'recordClass' => EventType::class,
            'data' => [
                [
                    'id' => 1,
                    'name' => 'Birthday',
                ],
            ],
        ],
        // OverwriteFiller delete all records before filling
        [
            'class' => OverwriteFiller::class,
            'recordClass' => EventType::class,
            'data' => [
                [
                    'id' => 1,
                    'canonicalName' => 'Birthday',
                    'class' => 'lulz',
                    // Fill relations
                    'translations' => [
                        [
                            'name' => 'День рождения',
                            'languageId' => '5',
                        ],
                    ],
                ],
            ],
        ],
        // AddFiller add records if they not exists in table with such id or attributes.
        [
            'class' => AddFiller::class,
            'recordClass' => EventType::class,
            'data' => [
                // check exists by id
                [
                    'id' => 1,
                    'name' => 'Birthday',
                ],
                // check exists by canonicalName
                [
                    'name' => 'Meeting',
                ],
            ],
        ],
    ],
]);
$seeder->fill();