メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Model::addBindParam

Add Bind Parameter types

Description​

public self Model::addBindParam( string $column, string $type )

The value of the column is cast to the type before it is written by insertRow, insertRows, updateRow, updateRowsWhere, insert, update and updateWhere. null values are not cast. Reads are not affected.

Throws InvalidArgumentException for an unknown type.

Arguments​

NameData typeDefaultRemarks
$columnstringColumn name
$typestringBind type (case-insensitive)

Types​

TypeCast
INTEGER(int)
FLOAT(float)
DATEY-m-d. A number is read as a Unix timestamp, anything else with strtotime()
DATETIMEY-m-d H:i:s. A number is read as a Unix timestamp, anything else with strtotime()

A DATE / DATETIME string that strtotime() cannot read is stored as 1970-01-01; validate dates before writing them.

Example​

Controller
$model = new Model();
$model->addBindParam('category', 'INTEGER');
$model->addBindParam('image_id', 'INTEGER');
$model->addBindParam('file_id', 'INTEGER');
$model->addBindParam('post_date', 'DATETIME');

// Same as the following
$model = new Model();
$model->setBindParam(array(
'category' => 'INTEGER',
'image_id' => 'INTEGER',
'file_id' => 'INTEGER',
'post_date' => 'DATETIME',
));