Пример #1
0
 public function actionComment($id)
 {
     $model = new Comment();
     $model->load(Yii::$app->request->post());
     $model->article_id = $id;
     if ($model->validate()) {
         $model->save();
         Yii::$app->session->setFlash("success", "Ок");
     }
     $this->redirect(["article/view", "id" => $id]);
 }
Пример #2
0
 public function actionNewComment()
 {
     if ($this->isAjax()) {
         $model = new Comment();
         $model->load($this->getParams());
         $validate = $model->validate();
         $reCaptcha = new ReCaptcha();
         $response = $reCaptcha->check();
         if ($validate && $response->isValid() && $model->save(false)) {
             return $this->getSuccessResponse(['email' => $model->email, 'text' => $model->text]);
         } else {
             $res = [];
             if (!$validate) {
                 $res['modelErrors'] = ActiveForm::validate($model);
             }
             if (!$response->isValid()) {
                 $res['reCaptchaError'] = true;
             }
             return $res;
         }
     }
     return Yii::$app->params['response']['error'];
 }