示例#1
0
 /**
  * Creates a new CommentRecord model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($type, $parent_id)
 {
     $model = new CommentRecord();
     // init parent_id attribute
     $model->parent_id = $parent_id;
     $model->type = $type;
     $model->setParentParams(['type' => $type, 'parent_id' => $parent_id]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#2
0
 public function actionCreate()
 {
     $validator = new \yii\captcha\CaptchaValidator();
     $post = Yii::$app->request->post();
     $res = $validator->validate($post['captcha'], $err);
     if ($res) {
         $comment = new CommentRecord();
         $comment->parent_id = $post['parent_id'];
         $comment->type = $post['type'];
         $comment->text = $post['text'];
         $comment->user_name = $post['user_name'];
         $comment->active = CommentRecord::STATUS_IS_NOT_ACTIVE;
         $comment->save();
         Yii::$app->getSession()->setFlash('success', 'Ваш комментарий добавлен и после модерации появится на сайте');
     } else {
         Yii::$app->getSession()->setFlash('error', 'Код введен не верно');
     }
     $this->redirect($post['back_url']);
 }