當前位置: 首頁>>代碼示例>>PHP>>正文


PHP models\Comment類代碼示例

本文整理匯總了PHP中common\models\Comment的典型用法代碼示例。如果您正苦於以下問題:PHP Comment類的具體用法?PHP Comment怎麽用?PHP Comment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Comment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionAddComment

 public function actionAddComment()
 {
     if (\Yii::$app->request->isAjax) {
         $model = new Comment();
         if (\Yii::$app->user->isGuest) {
             $model->scenario = 'isGuest';
         }
         $data = ['error' => true];
         if ($model->load(\Yii::$app->request->post())) {
             $parentID = \Yii::$app->request->post('parent_id');
             $root = $model->makeRootIfNotExist();
             if (!$parentID) {
                 $model->appendTo($root);
             } else {
                 $parent = Comment::find()->where(['id' => $parentID])->one();
                 $model->appendTo($parent);
             }
             $articleModel = Article::findOne($model->model_id);
             $data = ['replaces' => [['what' => '#comments', 'data' => $this->renderAjax('@app/themes/basic/modules/article/views/default/_comments', ['model' => $articleModel])]]];
         }
         return Json::encode($data);
     } else {
         throw new NotFoundHttpException(\Yii::t('app', 'Page not found'));
     }
 }
開發者ID:tolik505,項目名稱:bl,代碼行數:25,代碼來源:DefaultController.php

示例2: findComments

 /**
  * 
  * @param int $data
  * @return \yii\data\ActiveDataProvider
  */
 public static function findComments($data = array())
 {
     if (!isset($data['limit'])) {
         $data['limit'] = 10;
     }
     $model = new Comment();
     $dataProvider = new ActiveDataProvider(['query' => $model->find()->Where('is_public=:isp and top_id=0 and c_type="article" ', [':isp' => $data['is_public']])->orderBy(" id desc ")->limit($data['limit']), 'pagination' => ['pagesize' => $data['limit']]]);
     return $dataProvider;
 }
開發者ID:wxzuan,項目名稱:wxzuan,代碼行數:14,代碼來源:CommentService.php

示例3: actionComment

 public function actionComment($id)
 {
     $model = new Comment();
     $model->load(Yii::$app->request->post());
     $model->article_id = $id;
     if ($model->validate()) {
         $model->save();
         Yii::$app->session->setFlash("success", "Ок");
     }
     $this->redirect(["article/view", "id" => $id]);
 }
開發者ID:horechek,項目名稱:nnews,代碼行數:11,代碼來源:ArticleController.php

示例4: actionView

 public function actionView($slug)
 {
     $commentForm = new Comment();
     if ($commentForm->load(Yii::$app->request->post())) {
         if ($commentForm->save()) {
             Yii::$app->session->setFlash('success', '評論發表成功');
         } else {
             Yii::$app->session->setFlash('error', '評論發表失敗');
         }
     }
     return $this->render('view', ['article' => Page::getInstance()->getBySlug($slug), 'commentForm' => $commentForm]);
 }
開發者ID:luobenyu,項目名稱:blog-1,代碼行數:12,代碼來源:PageController.php

示例5: actionIndex

 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $model = new Comment();
     if ($model->load(Yii::$app->request->post())) {
         $model->is_active = 0;
         $model->created_at = date('Y-m-d H:i:s');
         $model->updated_at = date('Y-m-d H:i:s');
         $model->save();
         Yii::$app->session->setFlash('success', 'Thank you! Your comment has been added successfully. It will be available after moderation ;)');
         return $this->redirect('/');
     }
     return $this->render('comments', ['model' => $model]);
 }
開發者ID:roman-gich,項目名稱:comments,代碼行數:18,代碼來源:SiteController.php

示例6: actionAddComment

 public function actionAddComment()
 {
     $productId = Yii::$app->request->post('productId');
     $rank = Yii::$app->request->post('rank');
     $content = Yii::$app->request->post('content');
     $comment = new Comment();
     $comment->attributes = ['product_id' => $productId, 'user_id' => Yii::$app->user->identity->id, 'rank' => $rank, 'content' => $content];
     if ($comment->save(true)) {
         return ['status' => true, 'message' => '成功'];
     } else {
         return ['status' => false, 'message' => '失敗: ' . Html::errorSummary($comment)];
     }
 }
開發者ID:su-xiaolin,項目名稱:ICShop-Yii,代碼行數:13,代碼來源:ProductController.php

示例7: save

 /**
  * 保存商品
  */
 public function save()
 {
     $newComent = new Comment();
     $newComent->setAttributes($this->attributes);
     $newComent->setAttribute('c_type', 'article');
     $newComent->setAttribute("c_addtime", date('Y-m-d H:i:s'));
     if ($newComent->save()) {
         $logisct_id = \Yii::$app->db->lastInsertID;
         return $logisct_id;
     } else {
         return FALSE;
     }
 }
開發者ID:wxzuan,項目名稱:wxzuan,代碼行數:16,代碼來源:SayingForm.php

示例8: actionView

 /**
  * Displays a single Post model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $list_comment = new ActiveDataProvider(['query' => Comment::find()->where(['post_id' => $id, 'status' => 1])]);
     $model_comment = new Comment();
     if ($model_comment->load(Yii::$app->request->post())) {
         $model_comment->post_id = $id;
         $model_comment->status = 0;
         if ($model_comment->save()) {
             Yii::$app->session->setFlash('success', 'Ваш комментарий был отправлен администраторам сайта и будет опубликован после проверки..');
         } else {
             Yii::$app->session->setFlash('error', 'Ваш комментарий не был отправлен по техническим причинам. Попробуйте ещё раз.');
         }
     }
     return $this->render('view', ['model' => $this->findModel($id), 'list_comment' => $list_comment, 'model_comment' => $model_comment]);
 }
開發者ID:kuzma17,項目名稱:paveldent,代碼行數:20,代碼來源:PostController.php

示例9: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $commentTable = Comment::tableName();
     $user = Yii::$app->getModule("user")->model("User");
     // set up query with relation to `user.username`
     $userTable = $user::tableName();
     $query->joinWith(['user' => function ($query) use($userTable) {
         $query->from(['user' => $userTable]);
     }]);
     $profileTable = \common\modules\user\models\Profile::tableName();
     $query->joinWith(['profile' => function ($query) use($profileTable) {
         $query->from(['profile' => $profileTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     // enable sorting for the related columns
     $addSortAttributes = ["user.username", 'profile.full_name'];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $createdTime = strtotime($this->created_at);
     $startDay = date("Y-m-d 00:00:00", $createdTime);
     $endDay = date("Y-m-d 00:00:00", $createdTime + 60 * 60 * 24);
     if ($this->created_at) {
         $query->andFilterWhere(['between', 'created_at', $startDay, $endDay]);
     }
     $query->andFilterWhere(["{$commentTable}.id" => $this->id, "{$commentTable}.user_id" => $this->user_id, 'parent_id' => $this->parent_id]);
     $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user.username', $this->getAttribute('user.username')])->andFilterWhere(['like', 'profile.full_name', $this->getAttribute('profile.full_name')]);
     return $dataProvider;
 }
開發者ID:alexsynytskiy,項目名稱:Dynamomania,代碼行數:40,代碼來源:CommentSearch.php

示例10: run

 public function run()
 {
     $commentModel = new Comment();
     if (\Yii::$app->user->isGuest) {
         $commentModel->scenario = 'isGuest';
     }
     $commentModel->model_name = $this->model->formName();
     $commentModel->model_id = $this->model->id;
     $root = $commentModel->getRoot();
     if ($root) {
         $commentModels = $root->getChildren();
     } else {
         $commentModels = [];
     }
     return $this->render('default', ['commentModel' => $commentModel, 'model' => $this->model, 'commentModels' => $commentModels]);
 }
開發者ID:tolik505,項目名稱:bl,代碼行數:16,代碼來源:Widget.php

示例11: actionArticle

 /**
  * 顯示一個文章的信息
  * @return type
  */
 public function actionArticle()
 {
     $id = \Yii::$app->request->get('id');
     $idTrue = true;
     if (empty($id)) {
         $idTrue = FALSE;
     }
     if ($idTrue) {
         $articleInfo = Comment::find()->where('id=:id', [':id' => $id])->one();
         if (!$articleInfo) {
             $idTrue = FALSE;
         } else {
             if ($articleInfo->is_public === 0 && \Yii::$app->user->getId() !== $articleInfo->to_user_id && \Yii::$app->user->getId() !== $articleInfo->user_id) {
                 $idTrue = FALSE;
             }
         }
     }
     if (!$idTrue) {
         $error = '當前評論不存在或者已經被禁止顯示';
         $notices = array('type' => 2, 'msgtitle' => '錯誤的訪問', 'message' => $error, 'backurl' => Url::toRoute('/say/index'), 'backtitle' => '返回');
         Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
         $this->redirect(Url::toRoute('/public/notices'));
     }
     return $this->render('article', ['articleInfo' => $articleInfo]);
 }
開發者ID:wxzuan,項目名稱:wxzuan,代碼行數:29,代碼來源:SayController.php

示例12: actionIndex

 public function actionIndex()
 {
     $page = $this->helpGquery('page', 1);
     $size = 9;
     $offset = ($page - 1) * $size;
     $comment = new Comment();
     $values = $comment->getComments(null, $offset, $size, null);
     $comments = $values['list'];
     array_walk($comments, function (&$value, $key) {
         $value['addtime'] = date('Y-m-d H:i', $value['addtime']);
     });
     $total = $values['total'];
     $pageHTML = $this->getPageHTML($page, $size, $total);
     $params = ['comments' => $comments, 'pageHTML' => $pageHTML];
     return $this->render('index', $params);
 }
開發者ID:VampireMe,項目名稱:admin-9939-com,代碼行數:16,代碼來源:CommentController.php

示例13: getComment

 /**
  * Возвращает комментарий.
  * @param int $id идентификатор комментария
  * @throws NotFoundHttpException
  * @return Comment
  */
 public function getComment($id)
 {
     if (($model = Comment::findOne($id)) !== null && $model->isPublished()) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested post does not exist.');
     }
 }
開發者ID:richardcj,項目名稱:Blog-Yii2,代碼行數:14,代碼來源:Comment.php

示例14: actionIndex

 public function actionIndex($id)
 {
     $user = User::findIdentity($id);
     $comments = Comment::getRecentComments();
     $sidebarCategories = Category::getSidebarCategories();
     $tags = Tag::getTagList();
     return $this->render('index', ['user' => $user, 'comments' => $comments, 'sidebarCategories' => $sidebarCategories, 'tags' => $tags]);
 }
開發者ID:BorisMatonickin,項目名稱:yiicms,代碼行數:8,代碼來源:ProfileController.php

示例15: actionView

 public function actionView($slug)
 {
     $post = Post::findOne(['slug' => $slug]);
     $comment = new Comment();
     $comment->name = '';
     $comment->email = '';
     $comment->body = '';
     if ($comment->load(Yii::$app->request->post())) {
         $comment->status = 0;
         if ($comment->save()) {
             Yii::$app->session->setFlash('success', ['type' => 'success', 'duration' => 12000, 'icon' => 'fa fa-chat', 'message' => 'You\'re comment successfully stored and will shown after approval.', 'title' => 'Saving Comment']);
         } else {
             Yii::$app->session->setFlash('error', ['type' => 'danger', 'duration' => 12000, 'icon' => 'fa fa-chat', 'message' => 'Sorry but we couldn\'t store your comment.', 'title' => 'Saving Comment']);
         }
     }
     return $this->render('view', ['post' => $post, 'comment' => $comment]);
 }
開發者ID:ninjacto,項目名稱:ninjacto.com,代碼行數:17,代碼來源:BlogController.php


注:本文中的common\models\Comment類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。