addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { /** * text类型不会自动填充默认值 */ if (is_null($this->content)) { $this->content = ''; } $this->create_time = time(); } public function beforeUpdate() { if ($this->deleted == 1) { $this->published = 0; } $this->update_time = time(); } public function afterCreate() { $cache = new MaxHelpIdCache(); $cache->rebuild(); } }