コード例 #1
0
 /**
  * Creates a new PhotoComment model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new PhotoComment();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #2
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']]);
 }