Model_Crud Class

Introduction

A lot of database operations come to basic CRUD (Create Retrieve Update Delete) operations. The Model_Crud class supplies there functionalities in a standardized way. The class helps you with:

Your first model

To use the Model_Crud class, create a class that extends \Model_Crud. Example:

<php

class Model_Users extends \Model_Crud
{
	// Set the table to use
	protected static $_table_name = 'users';
}

Now you have a basic model to work with.

Configuration

Configuring a model is done by setting a few parameters:

Param Type Default Description Example
$_table_name string required The table to use.
protected static $_table_name = 'table';
$_primary_key string
'id'
The table's id field.
protected static $_primary_key = 'custom_id';
$_rules array none Input validation rules
protected static $_rules = array(
	'name' => 'required',
	'email' => 'required|valid_email',
);
$_labels array none The validation labels.
protected static $_labels = array(
	'name' => 'Your Name',
	'email' => 'Email Address',
);
$_connection string none The database connection to use.
protected static $_connection = null;
$_defaults array none AN array of default values
protected static $_defaults = array(
	'field' => 'value',
	'other_field' => 'other value',
);