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


PHP Comment::findOne方法代码示例

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


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

示例1: findModel

 /**
  * Finds the Comment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Comment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Comment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:viktornord,项目名称:gh-php-blog,代码行数:15,代码来源:CommentController.php

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

示例3: save

 public function save()
 {
     $comment = Comment::findOne($this->commentID);
     $comment->setAttributes(['author' => $this->author, 'text' => $this->text, 'email' => $this->email, 'published' => $this->published, 'deleted' => $this->deleted]);
     if ($comment->save(false)) {
         \Yii::$app->session->setFlash('saved', 'Комментарий сохранён!');
     } else {
         \Yii::$app->session->setFlash('error', 'Комментарий не сохранён!');
     }
 }
开发者ID:BoBRoID,项目名称:new.k-z,代码行数:10,代码来源:CommentForm.php

示例4: actionAlarm

 public function actionAlarm()
 {
     $id = Yii::$app->request->post('id');
     $msg = Yii::$app->request->post('msg');
     $comment = Comment::findOne($id);
     if ($comment && !empty($msg)) {
         if (Alarm::addAlarm(Alarm::ENTITY_COMMENT, $comment->id, $msg)) {
             return json_encode(['content' => \frontend\widgets\CommentsWidget::widget(['entity' => $comment->entity, 'entity_id' => $comment->entity_id, 'showDialog' => false]), 'anchor' => $comment->id]);
         } else {
             return json_encode(['content' => '', 'anchor' => '']);
         }
     }
 }
开发者ID:IVsevolod,项目名称:zouk,代码行数:13,代码来源:CommentController.php

示例5: addVote

 public static function addVote($entity, $id, $voteAdd)
 {
     $user = User::thisUser();
     $vote = Vote::findOne(['entity' => $entity, 'entity_id' => $id, 'user_id' => $user->id]);
     if (empty($vote)) {
         $vote = new Vote();
         $vote->entity = $entity;
         $vote->entity_id = $id;
         $vote->user_id = $user->id;
     }
     /** @var VoteModel $model */
     $model = null;
     if ($entity == self::ENTITY_ITEM) {
         $model = Item::findOne($id);
         if ($user->reputation < Item::MIN_REPUTATION_ITEM_VOTE) {
             // Если только пользователь не отменяет свои дизлайки
             if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
                 return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
             }
         }
     } else {
         if ($entity == self::ENTITY_EVENT) {
             $model = Event::findOne($id);
             if ($user->reputation < Event::MIN_REPUTATION_EVENT_VOTE) {
                 // Если только пользователь не отменяет свои дизлайки
                 if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
                     return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
                 }
             }
         } else {
             if ($entity == self::ENTITY_SCHOOL) {
                 $model = School::findOne($id);
                 if ($user->reputation < School::MIN_REPUTATION_SCHOOL_VOTE) {
                     // Если только пользователь не отменяет свои дизлайки
                     if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
                         return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
                     }
                 }
             } else {
                 if ($entity == self::ENTITY_COMMENT) {
                     $model = Comment::findOne($id);
                     if ($user->reputation < Comment::MIN_REPUTATION_COMMENT_VOTE) {
                         // Если только пользователь не отменяет свои дизлайки
                         if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
                             return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
                         }
                     }
                 }
             }
         }
     }
     if (!empty($model)) {
         if ($vote->vote == self::VOTE_UP) {
             if ($voteAdd == self::VOTE_UP) {
                 // убираем up
                 $vote->vote = self::VOTE_NONE;
                 $model->addVote(-1);
                 $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_UP);
             } else {
                 // ставим down
                 $vote->vote = self::VOTE_DOWN;
                 $model->addVote(-2);
                 $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_UP);
                 $model->addReputation(VoteModel::ADD_REPUTATION_DOWN);
             }
         } elseif ($vote->vote == self::VOTE_DOWN) {
             if ($voteAdd == self::VOTE_UP) {
                 // ставим up
                 $vote->vote = self::VOTE_UP;
                 $model->addVote(2);
                 $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_DOWN);
                 $model->addReputation(VoteModel::ADD_REPUTATION_UP);
             } else {
                 // убираем down
                 $vote->vote = self::VOTE_NONE;
                 $model->addVote(1);
                 $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_DOWN);
             }
         } else {
             if ($voteAdd == self::VOTE_UP) {
                 // ставим up
                 $vote->vote = self::VOTE_UP;
                 $model->addVote(1);
                 $model->addReputation(VoteModel::ADD_REPUTATION_UP);
             } else {
                 // ставим down
                 $vote->vote = self::VOTE_DOWN;
                 $model->addVote(-1);
                 $model->addReputation(VoteModel::ADD_REPUTATION_DOWN);
             }
         }
     }
     if ($vote->save()) {
         if (!empty($model)) {
             $model->save();
         }
     }
     return ['vote' => $vote->vote, 'count' => $model->getVoteCount()];
 }
开发者ID:IVsevolod,项目名称:zouk,代码行数:99,代码来源:Vote.php

示例6: actionComplain

 /**
  * Url: /complain/{$id}
  * @param int $id Comment id
  * @return mixed
  * @throws BadRequestHttpException
  * @throws NotFoundHttpException
  */
 public function actionComplain($id)
 {
     $comment = Comment::findOne($id);
     if (!isset($comment)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     if (Yii::$app->user->isGuest) {
         throw new BadRequestHttpException('Для отправки жалобы авторизируйтесь.');
     }
     $claim = Claim::find()->where(['comment_id' => $comment->id, 'user_id' => Yii::$app->user->id])->one();
     if (!isset($claim->id)) {
         $claim = new Claim();
         $claim->comment_id = $comment->id;
         $claim->comment_author = $comment->user_id;
         $claim->user_id = Yii::$app->user->id;
     }
     if ($claim->load(Yii::$app->request->post())) {
         $claim->save();
     }
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | Жалоба на комментарий', 'columnFirst' => ['claim' => ['view' => '@frontend/views/forms/complain_form', 'data' => compact('comment', 'claim')]], 'columnSecond' => ['photo_news' => SiteBlock::getPhotoNews(), 'banner1' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner2' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner3' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner4' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner5' => SiteBlock::getBanner(Banner::REGION_NEWS)]]);
 }
开发者ID:alexsynytskiy,项目名称:Dynamomania,代码行数:28,代码来源:SiteController.php


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