public function actionComment() { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; $data = Yii::$app->request->post(); $user = User::findOne(Yii::$app->user->getId()); $whom = User::findOne($data['whom_id']); $rate = $whom->profile->rate; if ($rate == 0) { $whom->profile->rate = (double) $data['rate']; } else { $whom->profile->rate = ($rate + (double) $data['rate']) / 2; } $whom->profile->save(); $comment = new Comment(); $comment->rate = $data['rate']; $comment->description = $data['comment']; $comment->whom_id = $data['whom_id']; $comment->link('owner', $user); if ($comment->save()) { return array('success' => true); } return array('success' => false); } }
public function save() { if (!$this->validate()) { return false; } $comment = new Comment(['author' => $this->name, 'text' => $this->comment, 'ip' => \Yii::$app->request->getUserIP(), 'email' => $this->email, 'newsID' => $this->newsID, 'published' => $this->published]); return $comment->save(false); }
/** * 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]); } }
public function findByIdInsert($userId, $type, $typeId, $iNum, $iScore) { date_default_timezone_set('Asia/Shanghai'); $addTime = date('Y-m-d H:i:s', time()); $comment = new Comment(); $comment->userId = $userId; $comment->type = $type; $comment->typeId = $typeId; $comment->score = $iNum; $comment->content = $iScore; $comment->publishTime = $addTime; $comment->status = widgets\GlobalArray::$commentStatusConstantArray['PendingAudit']; $comment->save(); }
/** * @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]); }
/** * 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 (isset($_POST['Comment'])) { $model->attributes = $_POST['Comment']; $model->setAttribute('id', $model->id); $model->setAttribute('nama', Yii::$app->user->identity->nama); $model->setAttribute('post_id', Yii::$app->session['post_id']); $model->setAttribute('isi', $model->isi); if ($model->save()) { Yii::$app->getSession()->setFlash('success', 'Komentar Anda telah ditambahkan'); $this->redirect(['post/view', 'id' => $model->post_id]); } } else { return $this->render('create', ['model' => $model]); } }
/** * If validation is ok, gets POST data and saves to DB * @return bool */ public function addComment() { if ($this->validate()) { $comment = new Comment(); $comment->comment_writer = $this->comment_writer; $comment->comment_w_email = $this->comment_w_email; $comment->comment_w_phone = $this->comment_w_phone; $comment->comment_w_gender = $this->comment_w_gender; $comment->comment_country_id = $this->country; $comment->comment_subject = $this->comment_subject; $comment->comment_message = $this->comment_message; $comment->comment_date_created = time(); $comment->save(); return true; } return false; }
/** * 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]); }