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

Model::__construct

Model class constructor

Description​

public Model::__construct( [ boolean $is_admin = false, array $options = [] ] )

Throws InvalidArgumentException when table, id or visible is not a plain name, or when a bind type is unknown.

Arguments​

NameData typeDefaultRemarks
$is_adminbooleanfalsefalse: reads only return rows whose visible column is 1 (public pages). true: every row (CMS)
$optionsarray[]Model options (below)

Options​

KeyData typeRemarks
tablestringTable name. Same as setTableName
idstringPrimary key column. Same as setPrimary
visiblestringPublic flag column (optional). Same as setVisible
bindarrayColumn types cast on write (column => type). Same as setBindParam

table, id and visible must be plain names: letters, digits and _, optionally table.column. Other keys are ignored.

Example​

Controller
use Fegg\Model;

// For public pages (rows whose visible column is 0 are not returned)
$model = new Model(false, array(
// Operate on the `cms_news` table
'table' => 'cms_news',

// Primary key is `news_id`
'id' => 'news_id',

// Public flag is `visible`
'visible' => 'visible',

// Cast these columns on insert and update
'bind' => array(
'category' => 'INTEGER',
'image_id' => 'INTEGER',
'file_id' => 'INTEGER',
'post_date' => 'DATETIME',
),
));

// For CMS pages (every row, visible or not)
$admin = new Model(true, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));