Model_Crud クラス
はじめに
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:
- Creating database entries
- Retrieving database entries
- Updating database entries
- Deleting database entries
- Entree input validation
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.
設定
Configuring a model is done by setting a few parameters:
パラメータ | 型 | 規定値 | 説明 | 例 |
---|---|---|---|---|
$_table_name | string | 必須 | The table to use. |
|
$_primary_key | string |
|
The table's id field. |
|
$_rules | array | none | Input validation rules |
|
$_labels | array | none | The validation labels. |
|
$_properties | array | none | Columns to use when updating/saving. |
|
$_connection | string | none | The database connection to use, or the connection used for reads in a master/slave setup. If not configured, the DB config default will be used. |
|
$_write_connection | string | none | The database connection to use for writes in a master/slave setup. |
|
$_defaults | array | none | An array of default values |
|
$_created_at | string | none | Field name for a 'created at' field. Set $_mysql_timestamp to true to use a MySQL timestamp instead of a UNIX timestamp |
|
$_updated_at | string | none | Field name for a 'updated at' field. Set $_mysql_timestamp to true to use a MySQL timestamp instead of a UNIX timestamp |
|
$_mysql_timestamp | boolean | none | Set to true to use a MySQL timestamp instead of a UNIX timestamp for $_created_at and $_updated_at fields. |
|