メインコンテンツまでスキップ
Version: Fegg 5.x

Model::__construct

テーブルのモデルを作成します

説明​

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

table、id、visibleが単純な名前でない場合や、bindに不明な型がある場合はInvalidArgumentExceptionを投げます。

引数​

名前データ型デフォルト備考
$is_adminbooleanfalsefalse:読み込みではvisibleカラムが1の行だけを返します(公開ページ向け)。true:すべての行を返します(CMS向け)
$optionsarray[]モデルのオプション(下記)

オプション​

キーデータ型備考
tablestringテーブル名。setTableNameと同じです
idstring主キーのカラム。setPrimaryと同じです
visiblestring公開フラグのカラム(省略可)。setVisibleと同じです
bindarray書き込み時に型を変換するカラム(column => type)。setBindParamと同じです

table、id、visibleは単純な名前にします。使えるのは英数字と_で、table.columnの形も使えます。ほかのキーは無視します。

例​

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(
'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',
));