frontend\modules\topic\controllers\DefaultController::actionCreate PHP Method

actionCreate() public method

新建话题
public actionCreate ( ) : mixed
return mixed
    public function actionCreate()
    {
        $model = new Topic();
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            $topService = new TopicService();
            if (!$topService->filterContent($model->title) || !$topService->filterContent($model->content)) {
                $this->flash('请勿发表无意义的内容', 'warning');
                return $this->redirect('create');
            }
            if ($model->save()) {
                $this->flash('发表文章成功!', 'success');
                return $this->redirect(['view', 'id' => $model->id]);
            }
        } else {
            return $this->render('create', ['model' => $model]);
        }
    }