当前位置: 首页>>代码示例>>PHP>>正文


PHP Comment::find方法代码示例

本文整理汇总了PHP中common\models\Comment::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::find方法的具体用法?PHP Comment::find怎么用?PHP Comment::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common\models\Comment的用法示例。


在下文中一共展示了Comment::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: actionList

 public function actionList($event_id)
 {
     \Yii::$app->response->format = Response::FORMAT_JSON;
     $dp = new ActiveDataProvider();
     $dp->query = Comment::find()->with('user')->where(['event_id' => $event_id])->orderBy(['id' => SORT_DESC]);
     $dp->pagination->pageSize = 6;
     return ['items' => $dp->getModels(), 'pageCount' => $dp->getPagination()->getPageCount(), 'totalCount' => $dp->getTotalCount(), 'page' => $dp->pagination->page, 'count' => $dp->getCount()];
 }
开发者ID:KPEMATOP,项目名称:findspree_old,代码行数:8,代码来源:CommentController.php

示例5: 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

示例6: run

 public function run()
 {
     $query = Comment::find();
     if ($this->entity == Comment::ENTITY_ITEM || $this->entity == Comment::ENTITY_EVENT || $this->entity == Comment::ENTITY_SCHOOL) {
         $query = $query->andWhere(['entity' => $this->entity, 'entity_id' => $this->entity_id])->orderBy('date_create DESC');
     }
     $commentsAll = $query->all();
     $commentIds = [];
     $comments = [];
     $commentsParent = [];
     $commentsLink = [];
     /** @var Comment[] $commentsAll */
     foreach ($commentsAll as $comment) {
         if ($comment->parent_id == 0) {
             // Главный комментарий
             $commentsLink[$comment->id] = true;
             $commentIds[] = $comment->id;
             if ($comment->deleted == 0) {
                 $comments[] = $comment;
             }
         } else {
             // Ответ на комментарий
             $commentsLink[$comment->id] = $comment->parent_id;
         }
     }
     foreach ($commentsAll as $comment) {
         if ($comment->deleted == 0) {
             $commentId = $comment->parent_id;
             while (isset($commentsLink[$commentId])) {
                 if ($commentsLink[$commentId] === true) {
                     break;
                 } else {
                     if ($commentsLink[$commentId] != $commentId) {
                         $commentId = $commentsLink[$commentId];
                     } else {
                         $commentId = null;
                     }
                 }
             }
             if (!empty($commentId)) {
                 $commentsParent[$commentId][] = $comment;
                 $commentIds[] = $comment->id;
             }
         }
     }
     $thisUser = User::thisUser();
     /** @var Vote[] $voteItemsAll */
     $voteItemsAll = !empty($thisUser) ? $thisUser->getVotesByEntity(Vote::ENTITY_COMMENT, $commentIds) : [];
     $voteItems = [];
     foreach ($voteItemsAll as $voteItem) {
         $voteItems[$voteItem->entity_id] = $voteItem;
     }
     return $this->render('commentsWidget/list', ['comments' => $comments, 'voteItems' => $voteItems, 'commentsParent' => $commentsParent, 'entity' => $this->entity, 'entity_id' => $this->entity_id, 'showDialog' => $this->showDialog]);
 }
开发者ID:IVsevolod,项目名称:zouk,代码行数:54,代码来源:CommentsWidget.php

示例7: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $query->orderBy(['created_at' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if ($this->load($params) && !$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'product_id' => $this->product_id, 'order_id' => $this->order_id, 'star' => $this->star, 'point' => $this->point, 'up' => $this->up, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
开发者ID:CTaiDeng,项目名称:funshop,代码行数:19,代码来源:CommentSearch.php

示例8: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'section_id' => $this->section_id, 'parent' => $this->parent, 'status' => $this->status, 'thumbsup' => $this->thumbsup, 'thumbsdown' => $this->thumbsdown, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
开发者ID:tqsq2005,项目名称:digpage,代码行数:21,代码来源:CommentSearch.php

示例9: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find()->orderBy('id DESC');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'post_id' => $this->post_id, 'parent_id' => $this->parent_id, 'thumbsup' => $this->thumbsup, 'thumbsdown' => $this->thumbsdown, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
开发者ID:whystic,项目名称:yii2-whystic-blog,代码行数:21,代码来源:CommentSearch.php

示例10: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'article_id' => $this->article_id]);
     $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'comment', $this->comment]);
     return $dataProvider;
 }
开发者ID:horechek,项目名称:nnews,代码行数:21,代码来源:CommentSearch.php

示例11: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'create_time' => $this->create_time, 'post_id' => $this->post_id]);
     $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user_id', $this->user_id])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'url', $this->url]);
     return $dataProvider;
 }
开发者ID:hdushku,项目名称:npai,代码行数:21,代码来源:CommentSearch.php

示例12: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'is_active' => $this->is_active, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'value', $this->value])->andFilterWhere(['like', 'user_name', $this->user_name])->andFilterWhere(['like', 'user_email', $this->user_email]);
     return $dataProvider;
 }
开发者ID:roman-gich,项目名称:comments,代码行数:21,代码来源:CommentSearch.php

示例13: 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

示例14: actionDm

 public function actionDm()
 {
     \Yii::$app->response->format = Response::FORMAT_JSON;
     $article_id = \Yii::$app->request->post('article_id');
     $time = \Yii::$app->request->post('time');
     $page = \Yii::$app->request->post('page');
     $query = Comment::find()->where(['article_id' => $article_id]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $models = $query->offset($pages->offset)->orderBy('created_at desc')->limit($pages->limit)->with('user')->asArray()->all();
     $hasNext = 0;
     if ($page < $pages->pageCount) {
         $hasNext = 1;
     }
     return ['list' => $models, 'hasNext' => $hasNext, 'time' => $time];
 }
开发者ID:zhangsong,项目名称:yii,代码行数:16,代码来源:CommentController.php

示例15: actionView

 public function actionView($id)
 {
     $model = Article::find()->where(['id' => $id, 'status' => Article::STATUS_ACTIVE])->one();
     if ($model === null) {
         throw new NotFoundHttpException('not found');
     }
     // 浏览量变化
     $model->addView();
     $commentModel = new Comment();
     $commentQuery = Comment::find()->where(['article_id' => $id, 'parent_id' => 0]);
     $countCommentQuery = clone $commentQuery;
     $pages = new Pagination(['totalCount' => $countCommentQuery->count()]);
     $commentModels = $commentQuery->offset($pages->offset)->orderBy('created_at desc')->limit($pages->limit)->all();
     $hots = Article::find()->where(['category_id' => $model->category_id])->limit(10)->orderBy('view desc')->all();
     return $this->render('view', ['model' => $model, 'commentModel' => $commentModel, 'commentModels' => $commentModels, 'pages' => $pages, 'hots' => $hots]);
 }
开发者ID:zhangsong,项目名称:yii,代码行数:16,代码来源:ArticleController.php


注:本文中的common\models\Comment::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。