/** * Creates a new Comment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Comment(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => (string) $model->_id]); } else { return $this->render('create', ['model' => $model]); } }
/** * @return \yii\web\Response */ public function actionCreate() { $model = new Comment(); $model->ip = Yii::$app->request->userIP; $model->username = Yii::$app->session['__username']; $model->user_id = User::find()->where(['username' => $model->username])->one()->id; $model->created_at = time(); $model->updated_at = time(); //$params = FilterForm::filterHtml(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['show/view', 'id' => $model->news_id]); } echo '发布失败,请重新发表评论!'; }
public function actionIndex() { $query = Posts::find()->where(['status' => 'publish']); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 2]); $posts = $query->offset($pages->offset)->limit($pages->limit)->all(); $commenting = new Comment(); if ($commenting->load(Yii::$app->request->post())) { $commenting->commentor = Yii::$app->user->identity->username; $commenting->save(); return $this->redirect(['index']); } return $this->render('index', ['posts' => $posts, 'pages' => $pages, 'commenting' => $commenting]); }
/** * Displays a single Post model. * @param integer $id * @return mixed */ public function actionView($id) { $model = Post::find()->where(['id' => $id])->one(); $model->views++; $model->save(); $com = Comment::find()->all(); Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => $model->description]); Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => $model->seo_keywords]); $model_com = new Comment(); if ($model_com->load(Yii::$app->request->post()) && $model_com->save()) { //return $this->redirect(['view', 'id' => $model->id]); } else { /*return $this->render('create', [ 'model' => $model, ]);*/ } return $this->render('view', ['model' => $this->findModel($id), 'com' => $com, 'model_com' => $model_com]); }