/** * 我的评论 * @param string $id * @return string|\yii\web\Response */ public function actionMyComment($id = "") { if (Yii::$app->request->isPost && $id != '') { $model = Comment::findOne($id); if ($model->user_id == Yii::$app->user->identity->id) { Yii::$app->session->setFlash('my_comment_delete_success', '评论删除成功'); $model->delete(); } else { Yii::$app->session->setFlash('my_comment_delete_error', '评论删除失败'); } return $this->redirect(['account/my-comment']); } $searchModel = new CommentSearch(); $dataProvider = $searchModel->mySearch(Yii::$app->user->identity->id); return $this->render('my-comment', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]); }
/** * Lists all Comment models. * @return mixed */ public function actionIndex() { $searchModel = new CommentSearch(); $dataProvider = $searchModel->search(Yii::$app->request->getQueryParams()); return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]); }