PHP code example of forci / static-data-bundle

1. Go to this page and download the library: Download forci/static-data-bundle 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/ */

    

forci / static-data-bundle example snippets


new \Forci\Bundle\StaticData\ForciStaticDataBundle(),



// src/App/StaticData/RoleData.php

namespace App\StaticData;

use App\Entity\Role;
use Forci\Bundle\StaticData\StaticData\StaticData;

class RoleData extends StaticData {

    public function doLoad() {
        $records = [
            Role::ID_ADMINISTRATOR => [
                'name' => 'Administrator',
                'role' => 'ROLE_ADMIN'
            ],
            Role::ID_TRANSLATOR => [
                'name' => 'Translator',
                'role' => 'ROLE_TRANSLATOR'
            ],
        ];

        foreach ($records as $id => $role) {
            if (!$this->find(Role::class, $id)) {
                $entity = new Role();
                $entity->setId($id);
                $entity->setName($role['name']);
                $entity->setRole($role['role']);
                $this->persist($entity);
            }
        }
    }
}