Пример #1
0
 /**
  * Creates a new Notecomment model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Notecomment();
     $post = Yii::$app->request->post();
     if (isset($post['Notecomment']['content']) && isset($post['Notecomment']['noteId'])) {
         //             var_dump($post);die;
         $model->load($post);
         $model->noteId = $post['Notecomment']['noteId'];
         $model->userId = Yii::$app->user->identity->getId();
         $model->createTime = date('Y-m-d H:i:s', time());
         if ($post['Notecomment']['parentId']) {
             $comment = Notecomment::findOne($post['Notecomment']['parentId']);
             $model->commentId = 0 == $comment->commentId ? $comment->id : $comment->commentId;
         } else {
             $model->commentId = 0;
         }
         if ($model->save()) {
             return $this->redirect(['main/viewnote', 'id' => $post['Notecomment']['noteId']]);
         }
     } else {
         return $this->renderAjax('create', ['model' => $model]);
     }
     //**********
     //         if ($model->load(Yii::$app->request->post()) && $model->save()) {
     //             return $this->redirect(['view', 'id' => $model->id]);
     //         } else {
     //             return $this->render('create', [
     //                 'model' => $model,
     //             ]);
     //         }
 }