Exemplo n.º 1
0
 /**
  * Creates a new Topic model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Topic();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 /**
  * 创建新评论
  * @param $topic
  * @return Comment
  */
 protected function newTopic(Forum $forum)
 {
     $model = new Topic();
     $request = Yii::$app->request;
     if ($model->load($request->post())) {
         $model->author_id = Yii::$app->user->id;
         if ($forum->addTopic($model, true)) {
             if ($tags = $request->post('tags')) {
                 $tags = Tag::find()->where(['name' => explode(',', $tags)])->active()->all();
                 $model->addTags($tags);
             }
             $this->flash('发表话题成功!', 'success');
             return Yii::$app->end(0, $this->redirect(['topic/view', 'id' => $model->id]));
         }
     }
     return $model;
 }