PHP code example of fishingboy / codeigniter-seeder

1. Go to this page and download the library: Download fishingboy/codeigniter-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/ */

    

fishingboy / codeigniter-seeder example snippets




use fishingboy\ci_seeder\CI_Seeder_Controller;

class Seeder extends CI_Seeder_Controller
{
}



use fishingboy\ci_seeder\CI_Seeder_base;

class Sample_seeder extends CI_Seeder_base
{
    /**
     * Higher priority seeders run first.
     *
     * @var integer
     */
    public $priority = 100;

    /**
     * Insert seed data.
     *
     * @return integer Number of inserted rows.
     */
    public function run()
    {
        $this->CI->db->insert("users", [
            'name' => 'fishingboy',
        ]);

        return 1;
    }
}



use fishingboy\ci_seeder\CI_Seeder_base;

class Role_seeder extends CI_Seeder_base
{
    public $priority = 200;

    public function run()
    {
        $roles = [
            ['name' => 'admin'],
            ['name' => 'editor'],
            ['name' => 'member'],
        ];

        foreach ($roles as $role) {
            $this->CI->db->insert('roles', $role);
        }

        return count($roles);
    }
}
shell
php index.php seeder run Sample_seeder
text
php index.php seeder run Sample_seeder                     (priority: 100)
shell
php index.php seeder run Role_seeder
shell
php index.php seeder run Sample_seeder