/** * This method is called at the beginning of inserting or updating a record. * The default implementation will trigger an [[EVENT_BEFORE_INSERT]] event when `$insert` is true, * or an [[EVENT_BEFORE_UPDATE]] event if `$insert` is false. * * @param boolean $insert whether this method called while inserting a record. * If false, it means the method is called while updating a record. * @return boolean whether the insertion or updating should continue. * If false, the insertion or updating will be cancelled. */ public function beforeSave($insert) { $staticPageService = Yii::$app->staticPageService; $articles = $this->articles; foreach ($articles as &$article) { $articleContent = $this->generateHtmlFile($article); $article['contentUrl'] = $staticPageService->generateQiniuFile($articleContent); } $this->articles = $articles; return parent::beforeSave($insert); }