Beispiel #1
0
 /**
  * Displays a single Posts model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $searchModel = new CommentsSearch();
     $comments = Comments::findAll(['PostID' => $id]);
     $newComment = new Comments();
     $sql = "SELECT MAX(CommentID) AS CommentID FROM comments";
     $max_id = Comments::findBySql($sql)->one();
     $upload_id_comments = $max_id->CommentID;
     if ($newComment->load(Yii::$app->request->post())) {
         $newComment->TimeStamp = date("Y-m-d H:i:s");
         $newComment->Attachment = UploadedFile::getInstance($newComment, 'Attachment');
         if ($newComment->Attachment && $newComment->validate()) {
             $newComment->Attachment->saveAs('../uploads/comments/' . $newComment->Attachment->baseName . '_11111' . $upload_id_comments . '.' . $newComment->Attachment->extension);
             $newComment->Attachment = $newComment->Attachment->baseName . '_11111' . $upload_id_comments . '.' . $newComment->Attachment->extension;
         }
         if ($newComment->save()) {
             return $this->redirect(['view', 'id' => $newComment->PostID]);
         }
     } else {
         return $this->render('view', ['model' => $this->findModel($id), 'newComment' => $newComment, 'comments' => $comments]);
     }
 }