/** * Creates a new SongComment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new SongComment(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionAddComment() { try { $post = Yii::$app->getRequest()->post(); if (empty($post['id'])) { throw new \Exception('获取页面数据丢失'); } if (!$this->findModel($post['id'])) { throw new \Exception('日记信息异常'); } $DiaryComment = new SongComment(); $DiaryComment->song_id = $post['id']; $DiaryComment->comment_id = isset($post['comment_id']) ? $post['comment_id'] : 0; $DiaryComment->comment_type = isset($post['comment_type']) ? $post['comment_type'] : 0; $DiaryComment->user_id = Yii::$app->getUser()->getId(); $DiaryComment->comment_content = $post['comment_content']; $DiaryComment->status = 1; $DiaryComment->created_at = date('Y-m-d H:i:s'); $DiaryComment->save(); $error = $DiaryComment->getErrors(); } catch (\Exception $exp) { Yii::$app->getSession()->setFlash('error', $exp->getMessage()); } return $this->redirect(['view', 'id' => $post['id']]); }