addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { $this->create_time = time(); } public function beforeUpdate() { $this->update_time = time(); } public function beforeSave() { if (empty($this->icon)) { $this->icon = kg_default_icon_path(); } elseif (Text::startsWith($this->icon, 'http')) { $this->icon = self::getIconPath($this->icon); } } public function afterCreate() { $cache = new MaxCategoryIdCache(); $cache->rebuild(); } public function afterFetch() { if (!Text::startsWith($this->icon, 'http')) { $this->icon = kg_cos_icon_url($this->icon); } } public static function getIconPath($url) { if (Text::startsWith($url, 'http')) { return parse_url($url, PHP_URL_PATH); } return $url; } public static function types() { return [ self::TYPE_COURSE => '课程', self::TYPE_HELP => '帮助', self::TYPE_ARTICLE => '专栏', self::TYPE_QUESTION => '问答', ]; } }