コード例 #1
0
ファイル: PhotoController.php プロジェクト: xidiao/gxfenxi
 public function actionAddComment()
 {
     try {
         $post = Yii::$app->getRequest()->post();
         if (empty($post['id'])) {
             throw new \Exception('获取页面数据丢失');
         }
         if (!$this->findModel($post['id'])) {
             throw new \Exception('日记信息异常');
         }
         $PhotoComment = new PhotoComment();
         $PhotoComment->photo_id = $post['id'];
         $PhotoComment->comment_id = isset($post['comment_id']) ? $post['comment_id'] : 0;
         $PhotoComment->comment_type = isset($post['comment_type']) ? $post['comment_type'] : 0;
         $PhotoComment->user_id = Yii::$app->getUser()->getId();
         $PhotoComment->comment_content = $post['comment_content'];
         $PhotoComment->status = 1;
         $PhotoComment->created_at = date('Y-m-d H:i:s');
         $PhotoComment->save();
         $error = $PhotoComment->getErrors();
     } catch (\Exception $exp) {
         Yii::$app->getSession()->setFlash('error', $exp->getMessage());
     }
     return $this->redirect(['view', 'id' => $post['id']]);
 }