/** * 新建动弹 * @return mixed */ public function actionCreate() { $model = new Tweet(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $topService = new TweetService(); if (!$topService->filterContent($model->content)) { $this->flash('请勿发表无意义的内容', 'warning'); return $this->redirect('index'); } $model->user_id = Yii::$app->user->id; $model->type = $model::TYPE; if ($model->save()) { $this->flash('发表成功!', 'success'); } } return $this->redirect('index'); }
/** * 新建动弹 * @return mixed */ public function actionCreate() { $model = new Tweet(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $topService = new TweetService(); if (!$topService->filterContent($model->content)) { $this->flash('请勿发表无意义的内容', 'warning'); return $this->redirect('index'); } $model->user_id = Yii::$app->user->id; $model->type = $model::TYPE; $rawContent = $model->content; $model->content = TweetService::replaceTopic(TweetService::replace($rawContent)); if ($model->save()) { (new UserMeta())->saveNewMeta($model->type, $model->id, 'follow'); (new NotificationService())->newPostNotify(Yii::$app->user->identity, $model, $rawContent); $this->flash('发表成功!', 'success'); } } return $this->redirect('index'); }