예제 #1
0
 /**
  * Creates a new Comment model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Comment();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #2
0
 /**
  * Добавление комментария
  *
  * @return null|string
  */
 public function addComment()
 {
     if ($this->validate()) {
         $comment = new Comment();
         $comment->user_id = $this->user_id;
         $comment->post_id = $this->post_id;
         if ($this->reply_to) {
             $comment->reply_to = $this->reply_to;
         }
         $comment->ip = Yii::$app->request->getUserIP();
         $comment->is_register = 1;
         $comment->text_raw = $this->text;
         $comment->text = HtmlPurifier::process($this->text);
         if ($comment->save()) {
             return $comment->id;
         }
     }
     return null;
 }