yii model

  • model 加入事件监听
public function init()

{

    parent::init();

    $this->on(self::EVENT_BEFORE_UPDATE, [$this, 'beforeUpdate']);

    $this->on(self::EVENT_BEFORE_INSERT, [$this, 'beforeInsert']);

}



public function beforeInsert()

{
    //do something
}

你可能感兴趣的:(yii model)