1、什么是ActiveRecord
2、声明AR类
3、 操作CRUD
public function getPoststatus(){
$poststatus = Poststatus::find()->select(['name', 'id'])->indexBy('id')->column();
// $poststatus = Poststatus::find()->asArray()->all();
// $poststatus = ArrayHelper::map($poststatus, 'id', 'name');
return $poststatus;
}
直接将结果写在form中了
<?= $form->field($model, 'status')->dropDownList(
[Poststatus::find()->select(['name', 'id'])->indexBy('id')->column()],
['prompt'=>'请选择状态']
) ?>
二、生命周期
2.1 生命周期中的方法重写
save方法生命周期中所执行的方法 如: beforeSave
public function beforeSave($insert) { if(parent::beforeSave($insert)){ if($insert){ $this->create_time = time(); $this->update_time = time(); }else{ $this->update_time = time(); } return true; }else{ return false; } }
2-2