A complete platform for building web applications.

Seeder

Seeder allow your application to seed it's information and other data in database, file name must be in YYYYMMDDHHIISS + application name + .php format.

Command:

php creator make seeder todo

20160907085156_todo.php Created

The file:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Todo_Seeder extends ER_Seeder {

    /**
     * Class constructor
     *
     * @return  void
     */
    function __construct(){
        parent::__construct();
    }

    /**
     * prepare the seeds array
     *
     * @return  void
     */
    public function setup()
    {
        // seeds array
        // $this->seeds[''] = [];
    }

    // seeding 
    public function up()
    {
        // prepare seeds array
        $this->setup();
        // seeding the seeds
        $this->seeding();
    }

    // un-seeding 
    public function down()
    {
        // prepare seeds array
        $this->setup();
        // delete the seeded data
        foreach ($this->seeds as $table => $rows)
        {
            foreach ($rows as $key => $where)
            {
                get_instance()->db->delete($table, $where);
            }            
        }
    }
}
?>

Now we will edit the $this->seeds array to install our application in applications system.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Todo_Seeder extends ER_Seeder {

    /**
     * Class constructor
     *
     * @return  void
     */
    function __construct(){
        parent::__construct();
        get_instance()->load->model('Admin/App_model');
    }

    /**
     * prepare the seeds array
     *
     * @return  void
     */
    public function setup()
    {
        // seeds array
        $this->seeds['er_apps'] = array(
            array(
                'app_path'      => 'Todo',
                'app_icon'      => 'fa fa-list',
                'app_menu'      => App_model::MENU_SHOW,
                'app_access'    => App_model::ACCESS_AUTHORIZED,
                'app_status'    => App_model::STATUS_ACTIVE,
            ),
            array(
                'app_path'      => 'Todo/Category',
                'app_icon'      => 'fa fa-list',
                'app_menu'      => App_model::MENU_SHOW,
                'app_access'    => App_model::ACCESS_AUTHORIZED,
                'app_status'    => App_model::STATUS_ACTIVE
            ),
            array(
                'app_path'      => 'Todo/Task',
                'app_icon'      => 'fa fa-list',
                'app_menu'      => App_model::MENU_SHOW,
                'app_access'    => App_model::ACCESS_AUTHORIZED,
                'app_status'    => App_model::STATUS_ACTIVE
            ),
        );
    }

    // seeding 
    public function up()
    {
        // prepare seeds array
        $this->setup();
        // seeding the seeds
        $this->seeding();
    }

    // un-seeding 
    public function down()
    {
        // prepare seeds array
        $this->setup();
        // delete the seeded data
        foreach ($this->seeds as $table => $rows)
        {
            foreach ($rows as $key => $where)
            {
                get_instance()->db->delete($table, $where);
            }            
        }
    }
}
?>

We need some constants from Admin/App_modle model, so we load it.

The seeds array will insert Todo application , Todo/Category controller and Todo/Task controller.

Now execute the seeder command to seed the data.

php creator seed 20160907085156

Next is the Models.