A complete platform for building web applications.

Models

Models allow your application to deal with database, file name must be in {app-name}/{model-name}_model.php format.

Command:

php creator make model category Todo

php creator make model task Todo

models/Todo/Category_model.php
models/Todo/Task_model.php

The file:

<?php
/**
 * Ertikaz Category_model class
 *
 * This class object is the Category_model class
 *
 * @package     Ertikaz
 * @subpackage  model
 * @category    model
 */

class Category_model extends ER_Model {
/**
     * The table name for the model.
     *
     * @var string
     */
    public $table = '';

    /**
     * The primary key for the model.
     *
     * @var string
     */
    public $primaryKey = '';

    /**
     * The primary Label for the model.
     *
     * @var string
     */
    public $primaryLabel = '';

    /**
     * The default ordering parameters.
     *
     * @var string
     */
    public $orderBy = '';

    /**
     * The create by field name.
     *
     * @var string
     */
    public $createBy = '';

    /**
     * The create at field name.
     *
     * @var string
     */
    public $createAt = '';

    /**
     * The update by field name.
     *
     * @var string
     */
    public $updateBy = '';

    /**
     * The update at field name.
     *
     * @var string
     */
    public $updateAt = '';

    /**
     * The row permission like Linux file system permissions.
     * to understand this go to http://permissions-calculator.org/
     *
     * @var integer
     */
    public $permission = 700;

    /**
     * Strip HTML and PHP tags from a string.
     *
     * @var integer
     */
    public $stripTags = true;

    /**
     * The array of the forms input fields.
     *
     * @var array
     */
    public $forms = [
        '*' => [],
        'list' => [],
        'edit' => [], 
        'show' => [],
        'search' => [],
        'create' => [],
        'delete' => []
    ];

    /**
     * The array of the row action buttons.
     *
     * @var array
     */
    public $action_buttons = [
        '*' => [
            'url' => '',
            'class' => '',
            'method' => 'get',
        ],
        'show' => [
            'class' => 'glyphicon glyphicon-eye-open',
        ], 
        'edit' => [
            'class' => 'glyphicon glyphicon-edit',
        ], 
        'delete' => [
            'class' => 'glyphicon glyphicon-remove',
            'method' => 'post',
        ],
    ];

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

We need to edit the file to work with our tables.

  • $table => todo_categories.
  • $primaryKey => id.
  • $primaryLabel => name.
  • $orderBy => id ASC.
  • $createBy => create_by.
  • $createAt => create_at.
  • $updateBy => update_by.
  • $updateAt => update_at.

  • $forms

    $forms = [
        '*' => [
            'id'    => [
                'field' => 'id',
                'rules' => 'integer'
            ],
            'name'  => [
                'field' => 'name',
                'rules' => 'required'
            ],
            'status'  => [
                'field' => 'status',
                'rules' => 'required',
                'type'  => 'select:hasOne[Admin/Setting][value][name^=status]'
            ],
        ],
        'list' => [
            'id'      => [],
            'name'    => [],
            'status'  => [],
        ],
        'search' => [
            'name'      => [],
        ],
        'create' => [
            'name'    => [],
            'status'  => [],
        ],
        'edit' => [
            'id'    => [
                'type'  =>'hidden'
            ],
            'name'    => [],
            'status'  => [],
        ],
        'show' => [
            'id'      => [],
            'name'    => [],
            'status'  => [],
        ],
        'delete' => [
            'id'   => [
                'type'  => 'hidden'
            ],
        ],
    ];
    
  • $action_buttons

    $action_buttons = [
        '*' => [
            'url' => 'Todo/Category',
            'class' => '',
            'method' => 'get',
        ],
        'show' => [
            'class' => 'glyphicon glyphicon-eye-open',
        ], 
        'edit' => [
            'class' => 'glyphicon glyphicon-edit',
        ], 
        'delete' => [
            'class' => 'glyphicon glyphicon-remove',
            'method' => 'post',
        ],
    ];
    
  • Add new method to get the category tasks

    public function tasks()
    {
        return $this->hasMany('Todo/Contact', 'id', 'category_id');
    }
    

And do the same with models/Todo/Task_model.php

Next is the Controllers.